Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 16a2970

Browse filesBrowse files
authored
Merge pull request #25061 from dstansby/twoslope
Ensure TwoSlopeNorm always has two slopes
2 parents 0ec308d + c00006b commit 16a2970
Copy full SHA for 16a2970

File tree

Expand file treeCollapse file tree

3 files changed

+25
-9
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+25
-9
lines changed
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
TwoSlopeNorm now auto-expands to always have two slopes
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
In the case where either ``vmin`` or ``vmax`` are not manually specified
4+
to `~.TwoSlopeNorm`, and where the data it is scaling is all less than or
5+
greater than the center point, the limits are now auto-expanded so there
6+
are two symmetrically sized slopes either side of the center point.
7+
8+
Previously ``vmin`` and ``vmax`` were clipped at the center point, which
9+
caused issues when displaying color bars.
10+
11+
This does not affect behaviour when ``vmin`` and ``vmax`` are manually
12+
specified by the user.

‎lib/matplotlib/colors.py

Copy file name to clipboardExpand all lines: lib/matplotlib/colors.py
+9-5Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1432,13 +1432,17 @@ def vcenter(self, value):
14321432

14331433
def autoscale_None(self, A):
14341434
"""
1435-
Get vmin and vmax, and then clip at vcenter
1435+
Get vmin and vmax.
1436+
1437+
If vcenter isn't in the range [vmin, vmax], either vmin or vmax
1438+
is expanded so that vcenter lies in the middle of the modified range
1439+
[vmin, vmax].
14361440
"""
14371441
super().autoscale_None(A)
1438-
if self.vmin > self.vcenter:
1439-
self.vmin = self.vcenter
1440-
if self.vmax < self.vcenter:
1441-
self.vmax = self.vcenter
1442+
if self.vmin >= self.vcenter:
1443+
self.vmin = self.vcenter - (self.vmax - self.vcenter)
1444+
if self.vmax <= self.vcenter:
1445+
self.vmax = self.vcenter + (self.vcenter - self.vmin)
14421446

14431447
def __call__(self, value, clip=None):
14441448
"""

‎lib/matplotlib/tests/test_colors.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_colors.py
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -665,16 +665,16 @@ def test_TwoSlopeNorm_scale():
665665
def test_TwoSlopeNorm_scaleout_center():
666666
# test the vmin never goes above vcenter
667667
norm = mcolors.TwoSlopeNorm(vcenter=0)
668-
norm([1, 2, 3, 5])
669-
assert norm.vmin == 0
668+
norm([0, 1, 2, 3, 5])
669+
assert norm.vmin == -5
670670
assert norm.vmax == 5
671671

672672

673673
def test_TwoSlopeNorm_scaleout_center_max():
674674
# test the vmax never goes below vcenter
675675
norm = mcolors.TwoSlopeNorm(vcenter=0)
676-
norm([-1, -2, -3, -5])
677-
assert norm.vmax == 0
676+
norm([0, -1, -2, -3, -5])
677+
assert norm.vmax == 5
678678
assert norm.vmin == -5
679679

680680

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.