Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ddb1f68

Browse files
authored
Merge pull request #17533 from QuLogic/auto-backport-of-pr-17408-on-v3.2.x
Backport PR #17408 on branch v3.2.x
2 parents 460805d + 5c7fb5b commit ddb1f68

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
@@ -3220,6 +3220,9 @@ def set_xlim(self, left=None, right=None, emit=True, auto=False,
32203220
left, right = sorted([left, right], reverse=bool(reverse))
32213221

32223222
self._viewLim.intervalx = (left, right)
3223+
# Mark viewlims as no longer stale without triggering an autoscale.
3224+
for ax in self._shared_x_axes.get_siblings(self):
3225+
ax._stale_viewlim_x = False
32233226
if auto is not None:
32243227
self._autoscaleXon = bool(auto)
32253228

@@ -3611,6 +3614,9 @@ def set_ylim(self, bottom=None, top=None, emit=True, auto=False,
36113614
bottom, top = sorted([bottom, top], reverse=bool(reverse))
36123615

36133616
self._viewLim.intervaly = (bottom, top)
3617+
# Mark viewlims as no longer stale without triggering an autoscale.
3618+
for ax in self._shared_y_axes.get_siblings(self):
3619+
ax._stale_viewlim_y = False
36143620
if auto is not None:
36153621
self._autoscaleYon = bool(auto)
36163622

lib/matplotlib/tests/test_axes.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6694,3 +6694,33 @@ def test_invisible_axes():
66946694
assert fig.canvas.inaxes((200, 200)) is not None
66956695
ax.set_visible(False)
66966696
assert fig.canvas.inaxes((200, 200)) is None
6697+
6698+
6699+
@pytest.mark.parametrize('auto', (True, False, None))
6700+
def test_unautoscaley(auto):
6701+
fig, ax = plt.subplots()
6702+
x = np.arange(100)
6703+
y = np.linspace(-.1, .1, 100)
6704+
ax.scatter(x, y)
6705+
6706+
post_auto = ax.get_autoscaley_on() if auto is None else auto
6707+
6708+
ax.set_ylim((-.5, .5), auto=auto)
6709+
assert post_auto == ax.get_autoscaley_on()
6710+
fig.canvas.draw()
6711+
assert_array_equal(ax.get_ylim(), (-.5, .5))
6712+
6713+
6714+
@pytest.mark.parametrize('auto', (True, False, None))
6715+
def test_unautoscalex(auto):
6716+
fig, ax = plt.subplots()
6717+
x = np.arange(100)
6718+
y = np.linspace(-.1, .1, 100)
6719+
ax.scatter(y, x)
6720+
6721+
post_auto = ax.get_autoscalex_on() if auto is None else auto
6722+
6723+
ax.set_xlim((-.5, .5), auto=auto)
6724+
assert post_auto == ax.get_autoscalex_on()
6725+
fig.canvas.draw()
6726+
assert_array_equal(ax.get_xlim(), (-.5, .5))

0 commit comments

Comments
 (0)