FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

FIX: better error message for shared axes and axis('equal') by jklymak · Pull Request #21318 · matplotlib/matplotlib · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
9 changes: 5 additions & 4 deletions lib/matplotlib/axes/_base.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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

Back | FazBrowse Home | New Git URL