Skip to content

Commit c7a6b12

Browse files
authored
Merge pull request #17408 from tacaswell/fix_unautoscale
FIX: cancel pending autoscale on manually setting limits
2 parents 880ade0 + 2f41868 commit c7a6b12

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

lib/matplotlib/axes/_base.py

+6
Original file line numberDiff line numberDiff line change
@@ -3335,6 +3335,9 @@ def set_xlim(self, left=None, right=None, emit=True, auto=False,
33353335
left, right = sorted([left, right], reverse=bool(reverse))
33363336

33373337
self._viewLim.intervalx = (left, right)
3338+
# Mark viewlims as no longer stale without triggering an autoscale.
3339+
for ax in self._shared_x_axes.get_siblings(self):
3340+
ax._stale_viewlim_x = False
33383341
if auto is not None:
33393342
self._autoscaleXon = bool(auto)
33403343

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

36063609
self._viewLim.intervaly = (bottom, top)
3610+
# Mark viewlims as no longer stale without triggering an autoscale.
3611+
for ax in self._shared_y_axes.get_siblings(self):
3612+
ax._stale_viewlim_y = False
36073613
if auto is not None:
36083614
self._autoscaleYon = bool(auto)
36093615

lib/matplotlib/tests/test_axes.py

+30
Original file line numberDiff line numberDiff line change
@@ -6251,6 +6251,36 @@ def test_ytickcolor_is_not_markercolor():
62516251
assert tick.tick1line.get_markeredgecolor() != 'white'
62526252

62536253

6254+
@pytest.mark.parametrize('auto', (True, False, None))
6255+
def test_unautoscaley(auto):
6256+
fig, ax = plt.subplots()
6257+
x = np.arange(100)
6258+
y = np.linspace(-.1, .1, 100)
6259+
ax.scatter(x, y)
6260+
6261+
post_auto = ax.get_autoscaley_on() if auto is None else auto
6262+
6263+
ax.set_ylim((-.5, .5), auto=auto)
6264+
assert post_auto == ax.get_autoscaley_on()
6265+
fig.canvas.draw()
6266+
assert_array_equal(ax.get_ylim(), (-.5, .5))
6267+
6268+
6269+
@pytest.mark.parametrize('auto', (True, False, None))
6270+
def test_unautoscalex(auto):
6271+
fig, ax = plt.subplots()
6272+
x = np.arange(100)
6273+
y = np.linspace(-.1, .1, 100)
6274+
ax.scatter(y, x)
6275+
6276+
post_auto = ax.get_autoscalex_on() if auto is None else auto
6277+
6278+
ax.set_xlim((-.5, .5), auto=auto)
6279+
assert post_auto == ax.get_autoscalex_on()
6280+
fig.canvas.draw()
6281+
assert_array_equal(ax.get_xlim(), (-.5, .5))
6282+
6283+
62546284
@check_figures_equal(extensions=["png"])
62556285
def test_polar_interpolation_steps_variable_r(fig_test, fig_ref):
62566286
l, = fig_test.add_subplot(projection="polar").plot([0, np.pi/2], [1, 2])

0 commit comments

Comments
 (0)