8000 Merge pull request #1557 from WeatherGod/invert_autoscale · matplotlib/matplotlib@07fa831 · GitHub
[go: up one dir, main page]

Skip to content

Commit 07fa831

Browse files
committed
Merge pull request #1557 from WeatherGod/invert_autoscale
inverting an axis shouldn't affect the autoscaling setting
2 parents 9b09708 + d1db488 commit 07fa831

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

lib/matplotlib/axes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2421,7 +2421,7 @@ def set_axis_bgcolor(self, color):
24212421
def invert_xaxis(self):
24222422
"Invert the x-axis."
24232423
left, right = self.get_xlim()
2424-
self.set_xlim(right, left)
2424+
self.set_xlim(right, left, auto=None)
24252425

24262426
def xaxis_inverted(self):
24272427
"""Returns *True* if the x-axis is inverted."""
@@ -2641,7 +2641,7 @@ def set_xticklabels(self, labels, fontdict=None, minor=False, **kwargs):
26412641
def invert_yaxis(self):
26422642
"Invert the y-axis."
26432643
bottom, top = self.get_ylim()
2644-
self.set_ylim(top, bottom)
2644+
self.set_ylim(top, bottom, auto=None)
26452645

26462646
def yaxis_inverted(self):
26472647
"""Returns *True* if the y-axis is inverted."""

lib/matplotlib/tests/test_axes.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,29 @@ def test_hexbin_extent():
419419

420420
ax.hexbin(x, y, extent=[.1, .3, .6, .7])
421421

422+
@cleanup
423+
def test_inverted_limits():
424+
# Test gh:1553
425+
# Calling invert_xaxis prior to plotting should not disable autoscaling
426+
# while still maintaining the inverted direction
427+
fig = plt.figure()
428+
ax = fig.gca()
429+
ax.invert_xaxis()
430+
ax.plot([-5, -3, 2, 4], [1, 2, -3, 5])
431+
432+
assert ax.get_xlim() == (4, -5)
433+
assert ax.get_ylim() == (-3, 5)
434+
plt.close()
435+
436+
fig = plt.figure()
437+
ax = fig.gca()
438+
ax.invert_yaxis()
439+
ax.plot([-5, -3, 2, 4], [1, 2, -3, 5])
440+
441+
assert ax.get_xlim() == (-5, 4)
442+
assert ax.get_ylim() == (5, -3)
443+
plt.close()
444+
422445
@image_comparison(baseline_images=['nonfinite_limits'])
423446
def test_nonfinite_limits():
424447
x = np.arange(0., np.e, 0.01)

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1389,7 +1389,7 @@ def invert_zaxis(self):
13891389
This function was added, but not tested. Please report any bugs.
13901390
"""
13911391
bottom, top = self.get_zlim()
1392-
self.set_zlim(top, bottom)
1392+
self.set_zlim(top, bottom, auto=None)
13931393

13941394
def zaxis_inverted(self):
13951395
'''

0 commit comments

Comments
 (0)
0