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

Commit 73304d2

Browse filesBrowse files
authored
Merge pull request #21318 from jklymak/fix-improve-shared-aspect-error
FIX: better error message for shared axes and axis('equal')
2 parents 241188e + e07c28f commit 73304d2
Copy full SHA for 73304d2

File tree

Expand file treeCollapse file tree

2 files changed

+12
-4
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+12
-4
lines changed

‎lib/matplotlib/axes/_base.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_base.py
+5-4Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1939,10 +1939,12 @@ def apply_aspect(self, position=None):
19391939

19401940
shared_x = self in self._shared_axes["x"]
19411941
shared_y = self in self._shared_axes["y"]
1942-
# Not sure whether we need this check:
1942+
19431943
if shared_x and shared_y:
1944-
raise RuntimeError("adjustable='datalim' is not allowed when both "
1945-
"axes are shared")
1944+
raise RuntimeError("set_aspect(..., adjustable='datalim') or "
1945+
"axis('equal') are not allowed when both axes "
1946+
"are shared. Try set_aspect(..., "
1947+
"adjustable='box').")
19461948

19471949
# If y is shared, then we are only allowed to change x, etc.
19481950
if shared_y:
@@ -2042,7 +2044,6 @@ def axis(self, *args, emit=True, **kwargs):
20422044
self.set_autoscale_on(True)
20432045
self.set_aspect('auto')
20442046
self.autoscale_view(tight=False)
2045-
# self.apply_aspect()
20462047
if s == 'equal':
20472048
self.set_aspect('equal', adjustable='datalim')
20482049
elif s == 'scaled':

‎lib/matplotlib/tests/test_axes.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_axes.py
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4954,6 +4954,13 @@ def test_shared_with_aspect_3():
49544954
assert round(expected, 4) == round(ax.get_aspect(), 4)
49554955

49564956

4957+
def test_shared_aspect_error():
4958+
fig, axes = plt.subplots(1, 2, sharex=True, sharey=True)
4959+
axes[0].axis("equal")
4960+
with pytest.raises(RuntimeError, match=r"set_aspect\(..., adjustable="):
4961+
fig.draw_without_rendering()
4962+
4963+
49574964
@pytest.mark.parametrize('twin', ('x', 'y'))
49584965
def test_twin_with_aspect(twin):
49594966
fig, ax = plt.subplots()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.