Skip to content

Commit 8e69c9b

Browse files
authored
Merge pull request #19978 from jpmattern/centerednorm-bugfix
fixed bug in CenteredNorm, issue #19972
2 parents 48fbf56 + d9aac95 commit 8e69c9b

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

lib/matplotlib/colors.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1359,6 +1359,8 @@ def __init__(self, vcenter=0, halfrange=None, clip=False):
13591359
array([0.25, 0.5 , 1. ])
13601360
"""
13611361
self._vcenter = vcenter
1362+
self.vmin = None
1363+
self.vmax = None
13621364
# calling the halfrange setter to set vmin and vmax
13631365
self.halfrange = halfrange
13641366
self.clip = clip
@@ -1382,7 +1384,7 @@ def autoscale(self, A):
13821384
def autoscale_None(self, A):
13831385
"""Set *vmin* and *vmax*."""
13841386
A = np.asanyarray(A)
1385-
if self.vmax is None and A.size:
1387+
if self._halfrange is None and A.size:
13861388
self.autoscale(A)
13871389

13881390
@property

lib/matplotlib/tests/test_colors.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,12 @@ def test_CenteredNorm():
418418
norm.autoscale_None([1, 2])
419419
assert norm.vmax + norm.vmin == 2 * vcenter
420420

421+
# Check that halfrange can be set without setting vcenter and that it is
422+
# not reset through autoscale_None.
423+
norm = mcolors.CenteredNorm(halfrange=1.0)
424+
norm.autoscale_None([1, 3000])
425+
assert norm.halfrange == 1.0
426+
421427
# Check that halfrange input works correctly.
422428
x = np.random.normal(size=10)
423429
norm = mcolors.CenteredNorm(vcenter=0.5, halfrange=0.5)

0 commit comments

Comments
 (0)