8000 Second attempt at fixing axis inversion (for mpl3.1). · matplotlib/matplotlib@7f7b048 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7f7b048

Browse files
committed
Second attempt at fixing axis inversion (for mpl3.1).
Turns out that the behavior of nonsingular() and limit_range_for_scale() w.r.t. respecting argument order is all over the place, so just re-sort the axis limits after-the-fact.
1 parent 5544485 commit 7f7b048

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3264,11 +3264,10 @@ def set_xlim(self, left=None, right=None, emit=True, auto=False,
32643264
cbook._warn_external(
32653265
f"Attempting to set identical left == right == {left} results "
32663266
f"in singular transformations; automatically expanding.")
3267-
swapped = left > right
3267+
reverse = left > right
32683268
left, right = self.xaxis.get_major_locator().nonsingular(left, right)
32693269
left, right = self.xaxis.limit_range_for_scale(left, right)
3270-
if swapped:
3271-
left, right = right, left
3270+
left, right = sorted([left, right], reverse=reverse)
32723271

32733272
self.viewLim.intervalx = (left, right)
32743273
if auto is not None:
@@ -3647,11 +3646,10 @@ def set_ylim(self, bottom=None, top=None, emit=True, auto=False,
36473646
f"Attempting to set identical bottom == top == {bottom} "
36483647
f"results in singular transformations; automatically "
36493648
f"expanding.")
3650-
swapped = bottom > top
3649+
reverse = bottom > top
36513650
bottom, top = self.yaxis.get_major_locator().nonsingular(bottom, top)
36523651
bottom, top = self.yaxis.limit_range_for_scale(bottom, top)
3653-
if swapped:
3654-
bottom, top = top, bottom
3652+
bottom, top = sorted([bottom, top], reverse=reverse)
36553653

36563654
self.viewLim.intervaly = (bottom, top)
36573655
if auto is not None:

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -623,11 +623,10 @@ def set_xlim3d(self, left=None, right=None, emit=True, auto=False,
623623
cbook._warn_external(
624624
f"Attempting to set identical left == right == {left} results "
625625
f"in singular transformations; automatically expanding.")
626-
swapped = left > right
626+
reverse = left > right
627627
left, right = self.xaxis.get_major_locator().nonsingular(left, right)
628628
left, right = self.xaxis.limit_range_for_scale(left, right)
629-
if swapped:
630-
left, right = right, left
629+
left, right = sorted([left, right], reverse=reverse)
631630
self.xy_viewLim.intervalx = (left, right)
632631

633632
if auto is not None:

0 commit comments

Comments
 (0)
0