-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fix pyplot.axis(ax) when ax is in other figure. #8043
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
Fix pyplot.axis(ax) when ax is in other figure. #8043
Conversation
Avoid crash when `ax` belongs to some other than the current figure. Make the `ax` owner the current figure instead.
9422ba3
to
37d7f1f
Compare
Is there any chance you could add a test in def test_set_axes_different_figure():
f1, a1 = plt.subplots()
f2, a2 = plt.subplots()
plt.axes(a1)
assert plt.gca() is a1
assert plt.gcf() is f1 This way we don't accidentally break it in the future. |
Sure, I'll get to it later today or tomorrow. |
Ensure `ax` becomes the current axis and its parent the current figure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Thanks!
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a couple of test fixes needed.
lib/matplotlib/tests/test_axes.py
Outdated
# test focusing of Axes in other Figure | ||
fig1, ax1 = subplots() | ||
fig2, ax2 = subplots() | ||
assert ax1 is plt.axes(ax1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These two lines need to be plt.subplots()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment is one line below where it should be.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Woops, thanks for spotting that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed - thanks for catching that.
lib/matplotlib/tests/test_axes.py
Outdated
@@ -1476,6 +1476,15 @@ def _as_mpl_axes(self): | |||
'Expected a PolarAxesSubplot, got %s' % type(ax) | |||
plt.close() | |||
|
|||
# test focusing of Axes in other Figure | |||
fig1, ax1 = subplots() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could the new lines go in a new function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed test_as_mpl_axes_api
seems to be for customizations with the _as_mpl_axes
function. I will add the new function.
Avoid crash when
ax
belongs to some other than the current figure.Make the
ax
owner the current figure instead.This resolves crash in
axes
call in the following stanza