@@ -970,7 +970,7 @@ class PiecewiseLinearNorm(Normalize):
970
970
971
971
Normalizes data into the ``[0.0, 1.0]`` interval.
972
972
"""
973
- def __init__ (self , vmin = None , vcenter = None , vmax = None , clip = False ):
973
+ def __init__ (self , vmin = None , vcenter = None , vmax = None ):
974
974
"""Normalize data with an offset midpoint
975
975
976
976
Useful when mapping data unequally centered around a conceptual
@@ -990,11 +990,6 @@ def __init__(self, vmin=None, vcenter=None, vmax=None, clip=False):
990
990
The data value that defines ``1.0`` in the normalized data.
991
991
Defaults to the the max value of the dataset.
992
992
993
- clip : bool, optional (default is False)
994
- If *clip* is True, values beyond *vmin* and *vmax* will be set
995
- to ``0.0`` or ``1.0``, respectively. Otherwise, values outside
996
- the ``[0.0, 1.0]`` will be returned.
997
-
998
993
Examples
999
994
--------
1000
995
>>> import matplotlib.colors as mcolors
@@ -1008,11 +1003,9 @@ def __init__(self, vmin=None, vcenter=None, vmax=None, clip=False):
1008
1003
self .vmin = vmin
1009
1004
self .vcenter = vcenter
1010
1005
self .vmax = vmax
1011
- self .clip = clip
1012
1006
1013
1007
def __call__ (self , value , clip = None ):
1014
- if clip is None :
1015
- clip = self .clip
1008
+ """Map value to the interval [0, 1]. The clip argument is unused."""
1016
1009
1017
1010
result , is_scalar = self .process_value (value )
1018
1011
@@ -1028,15 +1021,17 @@ def __call__(self, value, clip=None):
1028
1021
vmin = float (vmin )
1029
1022
vcenter = float (vcenter )
1030
1023
vmax = float (vmax )
1031
- if clip :
1032
- mask = ma .getmask (result )
1033
- result = ma .array (np .clip (result .filled (vmax ), vmin , vmax ),
1034
- mask = mask )
1024
+ # in degenerate cases, prefer the center value to the extremes
1025
+ degen = (result == vcenter ) if vcenter == vmax else None
1035
1026
1036
1027
x , y = [vmin , vcenter , vmax ], [0 , 0.5 , 1 ]
1037
- # returns a scalar if shape == (1,)
1038
- result = np .ma .masked_array (np .interp (value , x , y ))
1028
+ result = ma .masked_array (np .interp (result , x , y ),
1029
+ mask = ma .getmask (result ))
1030
+ if degen is not None :
1031
+ result [degen ] = 0.5
1039
1032
1033
+ if is_scalar :
1034
+ result = np .atleast_1d (result )[0 ]
1040
1035
return result
1041
1036
1042
1037
def autoscale_None (self , A ):
0 commit comments