Skip to content

fixed bug in CenteredNorm, issue #19972 #19978

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/matplotlib/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -1359,6 +1359,8 @@ def __init__(self, vcenter=0, halfrange=None, clip=False):
array([0.25, 0.5 , 1. ])
"""
self._vcenter = vcenter
self.vmin = None
self.vmax = None
# calling the halfrange setter to set vmin and vmax
self.halfrange = halfrange
self.clip = clip
Expand All @@ -1382,7 +1384,7 @@ def autoscale(self, A):
def autoscale_None(self, A):
"""Set *vmin* and *vmax*."""
A = np.asanyarray(A)
if self.vmax is None and A.size:
if self._halfrange is None and A.size:
self.autoscale(A)

@property
Expand Down
6 changes: 6 additions & 0 deletions lib/matplotlib/tests/test_colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,12 @@ def test_CenteredNorm():
norm.autoscale_None([1, 2])
assert norm.vmax + norm.vmin == 2 * vcenter

# Check that halfrange can be set without setting vcenter and that it is
# not reset through autoscale_None.
norm = mcolors.CenteredNorm(halfrange=1.0)
norm.autoscale_None([1, 3000])
assert norm.halfrange == 1.0

# Check that halfrange input works correctly.
x = np.random.normal(size=10)
norm = mcolors.CenteredNorm(vcenter=0.5, halfrange=0.5)
Expand Down