FIX: Guard against already-removed labels in ContourSet.remove()#31427
FIX: Guard against already-removed labels in ContourSet.remove()#31427buddy0452004 wants to merge 3 commits intomatplotlib:mainfrom
Conversation
|
@buddy0452004 I was working on a similar fix based on the discussion here. |
| the binding name, or by first importing it. | ||
|
|
||
|
|
||
| .. sphinx_gallery_thumbnail_path = 'gallery/user_interfaces/images/embedding_in_qt.png' |
There was a problem hiding this comment.
Hi, you seem to have included another PR in this PR. Can you start again, but base off upstream/main?
There was a problem hiding this comment.
Opps! sorry By mistake will do it again
@Chirag3841 Thanks for the note! Yes, a test makes sense here. I'll add one in the new PR. |
|
Closing in favor of #31431 which is based off upstream/main and includes a regression test. |
|
@buddy0452004 Note for the future: You don't have to/shouldn't close PRs and open a new one on the same topic. Instead it's recommended to push (or force-push) to update the existing PR. |
@timhoffm Thanks for the note, will keep that in mind for future PRs. |
When contour labels are manually removed before calling CS.remove(), matplotlib still tries to remove them again internally, causing a ValueError.
The root cause is that super().remove() detaches the contour from the axes, setting self.axes to None. Any subsequent access to self.axes.texts then crashes. The fix saves the axes reference before calling super().remove(), then uses it safely with a None check.
Closes #31404
AI Disclosure
No AI used.
PR Checklist