Skip to content

Commit 73304d2

Browse 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

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

lib/matplotlib/axes/_base.py

Lines 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

Lines 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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy