Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2587052

Browse files
committed
FIX: better error message for shared axes and axis('equal')
1 parent a6e01b5 commit 2587052

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1941,8 +1941,10 @@ def apply_aspect(self, position=None):
19411941
shared_y = self in self._shared_axes["y"]
19421942
# Not sure whether we need this check:
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') and "
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:
@@ -2044,7 +2046,11 @@ def axis(self, *args, emit=True, **kwargs):
20442046
self.autoscale_view(tight=False)
20452047
# self.apply_aspect()
20462048
if s == 'equal':
2047-
self.set_aspect('equal', adjustable='datalim')
2049+
try:
2050+
self.set_aspect('equal', adjustable='datalim')
2051+
except RuntimeError:
2052+
raise RuntimeError("'equal' is not allowed on shared "
2053+
"axes, try 'scaled' instead.")
20482054
elif s == 'scaled':
20492055
self.set_aspect('equal', adjustable='box', anchor='C')
20502056
self.set_autoscale_on(False) # Req. by Mark Bakker

0 commit comments

Comments
 (0)