@@ -1953,10 +1953,10 @@ class PowerNorm(Normalize):
19531953 Determines the behavior for mapping values outside the range
19541954 ``[vmin, vmax]``.
19551955
1956- If clipping is off, values outside the range ``[vmin, vmax]`` are also
1957- transformed by the power function, resulting in values outside ``[0, 1]``.
1958- This behavior is usually desirable, as colormaps can mark these *under*
1959- and *over* values with specific colors.
1956+ If clipping is off, values above *vmax* are transformed by the power
1957+ function, resulting in values above 1, and values below *vmin* are linearly
1958+ transformed resulting in values below 0. This behavior is usually desirable, as
1959+ colormaps can mark these *under* and *over* values with specific colors.
19601960
19611961 If clipping is on, values below *vmin* are mapped to 0 and values above
19621962 *vmax* are mapped to 1. Such values become indistinguishable from
@@ -1969,6 +1969,8 @@ class PowerNorm(Normalize):
19691969 .. math::
19701970
19711971 \left ( \frac{x - v_{min}}{v_{max} - v_{min}} \right )^{\gamma}
1972+
1973+ For input values below *vmin*, gamma is set to zero.
19721974 """
19731975 def __init__ (self , gamma , vmin = None , vmax = None , clip = False ):
19741976 super ().__init__ (vmin , vmax , clip )
@@ -1994,9 +1996,8 @@ def __call__(self, value, clip=None):
19941996 mask = mask )
19951997 resdat = result .data
19961998 resdat -= vmin
1997- resdat [resdat < 0 ] = 0
1998- np .power (resdat , gamma , resdat )
1999- resdat /= (vmax - vmin ) ** gamma
1999+ resdat /= (vmax - vmin )
2000+ resdat [resdat > 0 ] = np .power (resdat [resdat > 0 ], gamma )
20002001
20012002 result = np .ma .array (resdat , mask = result .mask , copy = False )
20022003 if is_scalar :
@@ -2006,14 +2007,21 @@ def __call__(self, value, clip=None):
20062007 def inverse (self , value ):
20072008 if not self .scaled ():
20082009 raise ValueError ("Not invertible until scaled" )
2010+
2011+ result , is_scalar = self .process_value (value )
2012+
20092013 gamma = self .gamma
20102014 vmin , vmax = self .vmin , self .vmax
20112015
2012- if np .iterable (value ):
2013- val = np .ma .asarray (value )
2014- return np .ma .power (val , 1. / gamma ) * (vmax - vmin ) + vmin
2015- else :
2016- return pow (value , 1. / gamma ) * (vmax - vmin ) + vmin
2016+ resdat = result .data
2017+ resdat [resdat > 0 ] = np .power (resdat [resdat > 0 ], 1 / gamma )
2018+ resdat *= (vmax - vmin )
2019+ resdat += vmin
2020+
2021+ result = np .ma .array (resdat , mask = result .mask , copy = False )
2022+ if is_scalar :
2023+ result = result [0 ]
2024+ return result
20172025
20182026
20192027class BoundaryNorm (Normalize ):
0 commit comments