Skip to content

Commit 15748b2

Browse files
committed
FIX: cancel pending autoscale on manually setting limits
closes #17331
1 parent 54bd6f1 commit 15748b2

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3332,6 +3332,9 @@ def set_xlim(self, left=None, right=None, emit=True, auto=False,
33323332
left, right = sorted([left, right], reverse=bool(reverse))
33333333

33343334
self._viewLim.intervalx = (left, right)
3335+
# Mark viewlims as no longer stale without triggering an autoscale.
3336+
for ax in self._shared_x_axes.get_siblings(self):
3337+
ax._stale_viewlim_x = False
33353338
if auto is not None:
33363339
self._autoscaleXon = bool(auto)
33373340

@@ -3601,6 +3604,9 @@ def set_ylim(self, bottom=None, top=None, emit=True, auto=False,
36013604
bottom, top = sorted([bottom, top], reverse=bool(reverse))
36023605

36033606
self._viewLim.intervaly = (bottom, top)
3607+
# Mark viewlims as no longer stale without triggering an autoscale.
3608+
for ax in self._shared_y_axes.get_siblings(self):
3609+
ax._stale_viewlim_y = False
36043610
if auto is not None:
36053611
self._autoscaleYon = bool(auto)
36063612

lib/matplotlib/tests/test_axes.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6213,6 +6213,16 @@ def test_ytickcolor_is_not_markercolor():
62136213
assert tick.tick1line.get_markeredgecolor() != 'white'
62146214

62156215

6216+
def test_unautoscale():
6217+
fig, ax = plt.subplots()
6218+
x = np.arange(100)
6219+
y = np.linspace(-.1, .1, 100)
6220+
ax.scatter(x, y)
6221+
ax.set_ylim((-.5, .5), auto=None)
6222+
fig.canvas.draw()
6223+
assert_array_equal(ax.get_ylim(), (-.5, .5))
6224+
6225+
62166226
@check_figures_equal(extensions=["png"])
62176227
def test_polar_interpolation_steps_variable_r(fig_test, fig_ref):
62186228
l, = fig_test.add_subplot(projection="polar").plot([0, np.pi/2], [1, 2])

0 commit comments

Comments
 (0)