Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ebd3753

Browse files
committed
Merge pull request #2 from jkseppan/add-asym-norm
Fixes
2 parents 57ca4fa + 426353c commit ebd3753

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

lib/matplotlib/colors.py

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -970,7 +970,7 @@ class PiecewiseLinearNorm(Normalize):
970970
971971
Normalizes data into the ``[0.0, 1.0]`` interval.
972972
"""
973-
def __init__(self, vmin=None, vcenter=None, vmax=None, clip=False):
973+
def __init__(self, vmin=None, vcenter=None, vmax=None):
974974
"""Normalize data with an offset midpoint
975975
976976
Useful when mapping data unequally centered around a conceptual
@@ -990,11 +990,6 @@ def __init__(self, vmin=None, vcenter=None, vmax=None, clip=False):
990990
The data value that defines ``1.0`` in the normalized data.
991991
Defaults to the the max value of the dataset.
992992
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-
998993
Examples
999994
--------
1000995
>>> import matplotlib.colors as mcolors
@@ -1008,11 +1003,9 @@ def __init__(self, vmin=None, vcenter=None, vmax=None, clip=False):
10081003
self.vmin = vmin
10091004
self.vcenter = vcenter
10101005
self.vmax = vmax
1011-
self.clip = clip
10121006

10131007
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."""
10161009

10171010
result, is_scalar = self.process_value(value)
10181011

@@ -1028,15 +1021,17 @@ def __call__(self, value, clip=None):
10281021
vmin = float(vmin)
10291022
vcenter = float(vcenter)
10301023
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
10351026

10361027
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
10391032

1033+
if is_scalar:
1034+
result = np.atleast_1d(result)[0]
10401035
return result
10411036

10421037
def autoscale_None(self, A):

lib/matplotlib/tests/test_colors.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ class BasePiecewiseLinearNorm(BaseNormMixin):
166166
normclass = mcolors.PiecewiseLinearNorm
167167
test_inverse = False
168168

169+
169170
class test_PiecewiseLinearNorm_Even(BasePiecewiseLinearNorm):
170171
def setup(self):
171172
self.norm = self.normclass(vmin=-1, vcenter=0, vmax=4)
@@ -298,6 +299,7 @@ def test_offset_norm_img():
298299
img2 = ax2.imshow(Z, cmap=cmap, norm=norm)
299300
cbar2 = fig.colorbar(img2, ax=ax2)
300301

302+
301303
def test_SymLogNorm():
302304
"""
303305
Test SymLogNorm behavior

0 commit comments

Comments
 (0)