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

Skip to content

Commit 6f9fd3a

Browse files
authored
Merge pull request #20166 from meeseeksmachine/auto-backport-of-pr-19978-on-v3.4.x
Backport PR #19978 on branch v3.4.x (fixed bug in CenteredNorm, issue #19972)
2 parents 592418a + 73c9dd0 commit 6f9fd3a

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
@@ -1341,6 +1341,8 @@ def __init__(self, vcenter=0, halfrange=None, clip=False):
13411341
array([0.25, 0.5 , 1. ])
13421342
"""
13431343
self._vcenter = vcenter
1344+
self.vmin = None
1345+
self.vmax = None
13441346
# calling the halfrange setter to set vmin and vmax
13451347
self.halfrange = halfrange
13461348
self.clip = clip
@@ -1364,7 +1366,7 @@ def autoscale(self, A):
13641366
def autoscale_None(self, A):
13651367
"""Set *vmin* and *vmax*."""
13661368
A = np.asanyarray(A)
1367-
if self.vmax is None and A.size:
1369+
if self._halfrange is None and A.size:
13681370
self.autoscale(A)
13691371

13701372
@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)