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 5544485

Browse filesBrowse files
authored
Merge pull request matplotlib#14623 from anntzer/loglocatororder31
Fix axis inversion with loglocator and logitlocator.
2 parents d49a8df + af1ab00 commit 5544485
Copy full SHA for 5544485

File tree

Expand file treeCollapse file tree

5 files changed

+29
-3
lines changed
Filter options
Expand file treeCollapse file tree

5 files changed

+29
-3
lines changed
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
API changes
2+
```````````
3+
4+
`Locator.nonsingular` (introduced in mpl 3.1) now returns a range ``v0, v1``
5+
with ``v0 <= v1``. This behavior is consistent with the implementation of
6+
``nonsingular`` by the `LogLocator` and `LogitLocator` subclasses.

‎lib/matplotlib/axes/_base.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_base.py
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3264,8 +3264,11 @@ 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
32673268
left, right = self.xaxis.get_major_locator().nonsingular(left, right)
32683269
left, right = self.xaxis.limit_range_for_scale(left, right)
3270+
if swapped:
3271+
left, right = right, left
32693272

32703273
self.viewLim.intervalx = (left, right)
32713274
if auto is not None:
@@ -3644,8 +3647,11 @@ def set_ylim(self, bottom=None, top=None, emit=True, auto=False,
36443647
f"Attempting to set identical bottom == top == {bottom} "
36453648
f"results in singular transformations; automatically "
36463649
f"expanding.")
3650+
swapped = bottom > top
36473651
bottom, top = self.yaxis.get_major_locator().nonsingular(bottom, top)
36483652
bottom, top = self.yaxis.limit_range_for_scale(bottom, top)
3653+
if swapped:
3654+
bottom, top = top, bottom
36493655

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

‎lib/matplotlib/tests/test_axes.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_axes.py
+6-1Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -938,7 +938,12 @@ def test_inverted_limits():
938938

939939
assert ax.get_xlim() == (-5, 4)
940940
assert ax.get_ylim() == (5, -3)
941-
plt.close()
941+
942+
# Test inverting nonlinear axes.
943+
fig, ax = plt.subplots()
944+
ax.set_yscale("log")
945+
ax.set_ylim(10, 1)
946+
assert ax.get_ylim() == (10, 1)
942947

943948

944949
@image_comparison(baseline_images=['nonfinite_limits'])

‎lib/matplotlib/ticker.py

Copy file name to clipboardExpand all lines: lib/matplotlib/ticker.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1521,8 +1521,8 @@ def raise_if_exceeds(self, locs):
15211521
return locs
15221522

15231523
def nonsingular(self, v0, v1):
1524-
"""Modify the endpoints of a range as needed to avoid singularities."""
1525-
return mtransforms.nonsingular(v0, v1, increasing=False, expander=.05)
1524+
"""Expand a range as needed to avoid singularities."""
1525+
return mtransforms.nonsingular(v0, v1, expander=.05)
15261526

15271527
def view_limits(self, vmin, vmax):
15281528
"""

‎lib/mpl_toolkits/mplot3d/axes3d.py

Copy file name to clipboardExpand all lines: lib/mpl_toolkits/mplot3d/axes3d.py
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,8 +623,11 @@ 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
626627
left, right = self.xaxis.get_major_locator().nonsingular(left, right)
627628
left, right = self.xaxis.limit_range_for_scale(left, right)
629+
if swapped:
630+
left, right = right, left
628631
self.xy_viewLim.intervalx = (left, right)
629632

630633
if auto is not None:
@@ -681,8 +684,11 @@ def set_ylim3d(self, bottom=None, top=None, emit=True, auto=False,
681684
f"Attempting to set identical bottom == top == {bottom} "
682685
f"results in singular transformations; automatically "
683686
f"expanding.")
687+
swapped = bottom > top
684688
bottom, top = self.yaxis.get_major_locator().nonsingular(bottom, top)
685689
bottom, top = self.yaxis.limit_range_for_scale(bottom, top)
690+
if swapped:
691+
bottom, top = top, bottom
686692
self.xy_viewLim.intervaly = (bottom, top)
687693

688694
if auto is not None:
@@ -739,8 +745,11 @@ def set_zlim3d(self, bottom=None, top=None, emit=True, auto=False,
739745
f"Attempting to set identical bottom == top == {bottom} "
740746
f"results in singular transformations; automatically "
741747
f"expanding.")
748+
swapped = bottom > top
742749
bottom, top = self.zaxis.get_major_locator().nonsingular(bottom, top)
743750
bottom, top = self.zaxis.limit_range_for_scale(bottom, top)
751+
if swapped:
752+
bottom, top = top, bottom
744753
self.zz_viewLim.intervalx = (bottom, top)
745754

746755
if auto is not None:

0 commit comments

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