Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3220,6 +3220,9 @@ def set_xlim(self, left=None, right=None, emit=True, auto=False,
left, right = sorted([left, right], reverse=bool(reverse))

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

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

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

Expand Down
30 changes: 30 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6694,3 +6694,33 @@ def test_invisible_axes():
assert fig.canvas.inaxes((200, 200)) is not None
ax.set_visible(False)
assert fig.canvas.inaxes((200, 200)) is None


@pytest.mark.parametrize('auto', (True, False, None))
def test_unautoscaley(auto):
fig, ax = plt.subplots()
x = np.arange(100)
y = np.linspace(-.1, .1, 100)
ax.scatter(x, y)

post_auto = ax.get_autoscaley_on() if auto is None else auto

ax.set_ylim((-.5, .5), auto=auto)
assert post_auto == ax.get_autoscaley_on()
fig.canvas.draw()
assert_array_equal(ax.get_ylim(), (-.5, .5))


@pytest.mark.parametrize('auto', (True, False, None))
def test_unautoscalex(auto):
fig, ax = plt.subplots()
x = np.arange(100)
y = np.linspace(-.1, .1, 100)
ax.scatter(y, x)

post_auto = ax.get_autoscalex_on() if auto is None else auto

ax.set_xlim((-.5, .5), auto=auto)
assert post_auto == ax.get_autoscalex_on()
fig.canvas.draw()
assert_array_equal(ax.get_xlim(), (-.5, .5))