Fix pyplot.axis(ax) when ax is in other figure.#8043
Fix pyplot.axis(ax) when ax is in other figure.#8043NelleV merged 4 commits intomatplotlib:masterfrom
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 f1This 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.
|
|
dstansby
left a comment
There was a problem hiding this comment.
Just a couple of test fixes needed.
| # 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.
These two lines need to be plt.subplots()
There was a problem hiding this comment.
This comment is one line below where it should be.
There was a problem hiding this comment.
Woops, thanks for spotting that
There was a problem hiding this comment.
Fixed - thanks for catching that.
lib/matplotlib/tests/test_axes.py
Outdated
| plt.close() | ||
|
|
||
| # test focusing of Axes in other Figure | ||
| fig1, ax1 = subplots() |
There was a problem hiding this comment.
Could the new lines go in a new function?
There was a problem hiding this comment.
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
axbelongs to some other than the current figure.Make the
axowner the current figure instead.This resolves crash in
axescall in the following stanza