Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

FIX: better error message for shared axes and axis('equal') #21318

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 23, 2021
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 9 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 7 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
Morty Proxy This is a proxified and sanitized view of the page, visit original site.