@@ -1953,10 +1953,10 @@ class PowerNorm(Normalize):
1953
1953
Determines the behavior for mapping values outside the range
1954
1954
``[vmin, vmax]``.
1955
1955
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.
1960
1960
1961
1961
If clipping is on, values below *vmin* are mapped to 0 and values above
1962
1962
*vmax* are mapped to 1. Such values become indistinguishable from
@@ -1969,6 +1969,8 @@ class PowerNorm(Normalize):
1969
1969
.. math::
1970
1970
1971
1971
\left ( \frac{x - v_{min}}{v_{max} - v_{min}} \right )^{\gamma}
1972
+
1973
+ For input values below *vmin*, gamma is set to zero.
1972
1974
"""
1973
1975
def __init__ (self , gamma , vmin = None , vmax = None , clip = False ):
1974
1976
super ().__init__ (vmin , vmax , clip )
@@ -1994,9 +1996,8 @@ def __call__(self, value, clip=None):
1994
1996
mask = mask )
1995
1997
resdat = result .data
1996
1998
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 )
2000
2001
2001
2002
result = np .ma .array (resdat , mask = result .mask , copy = False )
2002
2003
if is_scalar :
@@ -2006,14 +2007,21 @@ def __call__(self, value, clip=None):
2006
2007
def inverse (self , value ):
2007
2008
if not self .scaled ():
2008
2009
raise ValueError ("Not invertible until scaled" )
2010
+
2011
+ result , is_scalar = self .process_value (value )
2012
+
2009
2013
gamma = self .gamma
2010
2014
vmin , vmax = self .vmin , self .vmax
2011
2015
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
2017
2025
2018
2026
2019
2027
class BoundaryNorm (Normalize ):
0 commit comments