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
9 changes: 5 additions & 4 deletions lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1939,10 +1939,12 @@ def apply_aspect(self, position=None):

shared_x = self in self._shared_axes["x"]
shared_y = self in self._shared_axes["y"]
# Not sure whether we need this check:

if shared_x and shared_y:
raise RuntimeError("adjustable='datalim' is not allowed when both "
"axes are shared")
raise RuntimeError("set_aspect(..., adjustable='datalim') or "
"axis('equal') are not allowed when both axes "
"are shared. Try set_aspect(..., "
"adjustable='box').")

# If y is shared, then we are only allowed to change x, etc.
if shared_y:
Expand Down Expand Up @@ -2042,7 +2044,6 @@ def axis(self, *args, emit=True, **kwargs):
self.set_autoscale_on(True)
self.set_aspect('auto')
self.autoscale_view(tight=False)
# self.apply_aspect()
if s == 'equal':
self.set_aspect('equal', adjustable='datalim')
elif s == 'scaled':
Expand Down
7 changes: 7 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4938,6 +4938,13 @@ def test_shared_with_aspect_3():
assert round(expected, 4) == round(ax.get_aspect(), 4)


def test_shared_aspect_error():
fig, axes = plt.subplots(1, 2, sharex=True, sharey=True)
axes[0].axis("equal")
with pytest.raises(RuntimeError, match=r"set_aspect\(..., adjustable="):
fig.draw_without_rendering()


@pytest.mark.parametrize('twin', ('x', 'y'))
def test_twin_with_aspect(twin):
fig, ax = plt.subplots()
Expand Down