Skip to content

Fix FigureImage losing its transform when re-added via add_artist - #32380

Merged
tacaswell merged 2 commits into
matplotlib:mainfrom
ahmed5145:fix-figimage-readd
Oct 20, 2026
Merged

tacaswell merged 2 commits into
matplotlib:mainfrom
ahmed5145:fix-figimage-readd

Conversation

@ahmed5145

Copy link
Copy Markdown
Contributor

PR summary

Closes #31730.

Figure.figimage() creates a FigureImage without setting a transform. Its offsets are in pixels, so it only drew correctly because an unset transform defaults to identity. After .remove() and fig.add_artist(im), add_artist sees is_transform_set() is False and gives the image transSubfigure, so the image is drawn in the wrong place and doesn't show up.

FigureImage.__init__ now sets IdentityTransform() explicitly, which is what @rcomer suggested in the issue. This covers both figimage() and a FigureImage created directly, and a transform= kwarg still overrides it. The other half of the issue (draw order relative to the axes) was already fixed by #31746, so with both changes the remove/re-add cycle now draws correctly.

AI Disclosure

I used Claude Code (generative AI) to trace the cause through add_artist, draft the regression test, and help write this PR description (to make sure I am following standards).

PR quality check

  • Use an expressive title.
  • New and changed code is tested
  • Plotting related features are demonstrated in an example
  • New features and API changes have release notes
  • Documentation complies with general and docstring guidelines

N/A for example/release notes/docs: this is a bug fix that makes an existing workflow behave as expected, with no API change.

Comment thread lib/matplotlib/tests/test_image.py Resolved
@tacaswell

Copy link
Copy Markdown
Member

Technically correct and I think harmless, but I am still of the view we should be detecting and failing an artist getting re-added (I had a PR for that and could not get it in 😞 ) .

@tacaswell
tacaswell merged commit a97404c into matplotlib:main Oct 20, 2026
40 of 41 checks passed
@tacaswell

tacaswell commented Oct 20, 2026 •

Copy link
Copy Markdown
Member

Can not even reach appveyor, merging.

@QuLogic QuLogic added this to the v3.12.0 milestone Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Figure.add_artist() fails to re-render an image previously added via Figure.figimage() after .remove()

3 participants