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

Skip to content

Fix removal of Figure-level artists #26365

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

Merged
merged 1 commit into from
Jul 21, 2023

Conversation

QuLogic
Copy link
Member

@QuLogic QuLogic commented Jul 20, 2023

PR summary

PyCharm has been warning that Artist.figure should be a Figure|None, not a bool as is set in this block.

Based on the previous section of code, I think setting the figure to stale (if the Axes was not already set stale, meaning the Artist was on a Figure only) was the intended behaviour.

This code is 8 years old, so I don't expect @tacaswell remembers the intention here, but the commit message does say "marks the parent axes/figure as stale", which I think indicates this PR is what's intended.

PR checklist

PyCharm has been warning that `Artist.figure` should be a `Figure|None`,
not a `bool` as is set in this block.

Based on the previous section of code, I think setting the figure to
stale (if the Axes was not already set stale, meaning the Artist was on
a Figure *only*) was the intended behaviour.
@tacaswell
Copy link
Member

My recollection is that it was trying to make sure that you could not do

fig1, ax = plt.subplots()
fig2 = plt.figure()
ax.remove()
fig2.add_axes(ax)

@tacaswell tacaswell added this to the v3.8.0 milestone Jul 20, 2023
@QuLogic
Copy link
Member Author

QuLogic commented Jul 20, 2023

But this isn't done for Axes-level artists?

@tacaswell
Copy link
Member

I thought at was!

import matplotlib as plt
fig, (ax1, ax2) = plt.subplots(2)
ln, = ax1.plot([0, 1, 2])
ln.remove()
ax2.add_artist(ln)
%history
ln.axes
ln.axes is ax2
ln.set_clip_on(False)

is super broken! The line is "in" ax2, but still has all the transfroms of ax1 so panning ax2 does nothing, but it moves around relative to ax1.

@QuLogic
Copy link
Member Author

QuLogic commented Jul 21, 2023

I'm not sure why I came across it, but I see #25168 seems to be related to that, and there are two linked-but-unfinished PRs (one by you).

@tacaswell
Copy link
Member

Oh, that explains why I remember it having that behavior.

As it stands, I think it is reasonable to take this PR as-is to not put spurious warnings in IDEs / mypy and defer making sure that re-adding Artists / Axes stays "broken" to a different PR.

@ksunden ksunden merged commit d8e989d into matplotlib:main Jul 21, 2023
@QuLogic QuLogic deleted the figure-artist-removal branch July 21, 2023 19:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants