Skip to content

Commit 2f41868

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

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-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: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6213,6 +6213,36 @@ def test_ytickcolor_is_not_markercolor():
62136213
assert tick.tick1line.get_markeredgecolor() != 'white'
62146214

62156215

6216+
@pytest.mark.parametrize('auto', (True, False, None))
6217+
def test_unautoscaley(auto):
6218+
fig, ax = plt.subplots()
6219+
x = np.arange(100)
6220+
y = np.linspace(-.1, .1, 100)
6221+
ax.scatter(x, y)
6222+
6223+
post_auto = ax.get_autoscaley_on() if auto is None else auto
6224+
6225+
ax.set_ylim((-.5, .5), auto=auto)
6226+
assert post_auto == ax.get_autoscaley_on()
6227+
fig.canvas.draw()
6228+
assert_array_equal(ax.get_ylim(), (-.5, .5))
6229+
6230+
6231+
@pytest.mark.parametrize('auto', (True, False, None))
6232+
def test_unautoscalex(auto):
6233+
fig, ax = plt.subplots()
6234+
x = np.arange(100)
6235+
y = np.linspace(-.1, .1, 100)
6236+
ax.scatter(y, x)
6237+
6238+
post_auto = ax.get_autoscalex_on() if auto is None else auto
6239+
6240+
ax.set_xlim((-.5, .5), auto=auto)
6241+
assert post_auto == ax.get_autoscalex_on()
6242+
fig.canvas.draw()
6243+
assert_array_equal(ax.get_xlim(), (-.5, .5))
6244+
6245+
62166246
@check_figures_equal(extensions=["png"])
62176247
def test_polar_interpolation_steps_variable_r(fig_test, fig_ref):
62186248
l, = fig_test.add_subplot(projection="polar").plot([0, np.pi/2], [1, 2])

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy