Title: [Bug]: Figure.add_artist() fails to re-render an image previously added via Figure.figimage() after .remove() · Issue #31730 · matplotlib/matplotlib · GitHub
Open Graph Title: [Bug]: Figure.add_artist() fails to re-render an image previously added via Figure.figimage() after .remove() · Issue #31730 · matplotlib/matplotlib
X Title: [Bug]: Figure.add_artist() fails to re-render an image previously added via Figure.figimage() after .remove() · Issue #31730 · matplotlib/matplotlib
Description: Bug summary After calling .remove() on the FigureImage object returned by Figure.figimage(...) and then re-attaching it via Figure.add_artist(...), the image is no longer rendered in the saved figure. The same remove/re-add cycle works c...
Open Graph Description: Bug summary After calling .remove() on the FigureImage object returned by Figure.figimage(...) and then re-attaching it via Figure.add_artist(...), the image is no longer rendered in the saved figu...
X Description: Bug summary After calling .remove() on the FigureImage object returned by Figure.figimage(...) and then re-attaching it via Figure.add_artist(...), the image is no longer rendered in the saved figu...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/31730
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Bug]: Figure.add_artist() fails to re-render an image previously added via Figure.figimage() after .remove()","articleBody":"### Bug summary\n\nAfter calling `.remove()` on the `FigureImage` object returned by `Figure.figimage(...)` and then re-attaching it via `Figure.add_artist(...)`, the image is no longer rendered in the saved figure. The same remove/re-add cycle works correctly for a `Text` artist created via `Figure.text(...)`, suggesting `figimage` objects are not properly handled by `Figure.add_artist`.\n\n### Code for reproduction\n\n```Python\nimport matplotlib.pyplot as plt\nfrom matplotlib.figure import Figure\nfrom io import BytesIO\n\ndef text_to_rgba(s, *, dpi, **kwargs):\n fig = Figure(facecolor=\"none\")\n fig.text(0, 0, s, **kwargs)\n with BytesIO() as buf:\n fig.savefig(buf, dpi=dpi, format=\"png\", bbox_inches=\"tight\",\n pad_inches=0)\n buf.seek(0)\n rgba = plt.imread(buf)\n return rgba\n\n# --- Case 1: figimage ---\nfig, ax = plt.subplots()\nrgba1 = text_to_rgba(r\"IQ: $\\sigma_i=15$\", color=\"blue\", fontsize=10, dpi=200)\nfigimg = fig.figimage(rgba1, 100, 50)\nplt.savefig(\"figimage_before.png\") # image visible (correct)\nfigimg.remove()\nfig.add_artist(figimg)\nplt.savefig(\"figimage_after.png\") # image MISSING (bug)\n\n# --- Case 2: text (control) ---\nfig, ax = plt.subplots()\nmytext = fig.text(0.2, 0.15, r\"IQ: $\\sigma_i=15$\", color=\"blue\", fontsize=20)\nplt.savefig(\"text_before.png\") # text visible (correct)\nmytext.remove()\nfig.add_artist(mytext)\nplt.savefig(\"text_after.png\") # text visible (correct)\n```\n\n### Actual outcome\n\n#### figimage_before.png\n\n\u003cimg width=\"640\" height=\"480\" alt=\"Image\" src=\"https://github.com/user-attachments/assets/a17fb911-4773-4ae1-b206-854ae98c1ea9\" /\u003e\n\n#### figimage_after.png\n\n\u003cimg width=\"640\" height=\"480\" alt=\"Image\" src=\"https://github.com/user-attachments/assets/d9be189a-c10d-4386-a6fa-fa161071f74b\" /\u003e\n\n### Expected outcome\n\n#### figimage_before.png\n\n\u003cimg width=\"640\" height=\"480\" alt=\"Image\" src=\"https://github.com/user-attachments/assets/a17fb911-4773-4ae1-b206-854ae98c1ea9\" /\u003e\n\n#### figimage_after.png\n\n\u003cimg width=\"640\" height=\"480\" alt=\"Image\" src=\"https://github.com/user-attachments/assets/a17fb911-4773-4ae1-b206-854ae98c1ea9\" /\u003e\n\n### Additional information\n\n_No response_\n\n### Operating system\n\n_No response_\n\n### Matplotlib Version\n\n0.2.0.dev54524+unknown.ga94275af4\n\n### Matplotlib Backend\n\n_No response_\n\n### Python version\n\n_No response_\n\n### Jupyter version\n\n_No response_\n\n### Installation\n\nNone","author":{"url":"https://github.com/williamlus","@type":"Person","name":"williamlus"},"datePublished":"2026-05-22T12:50:56.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":8},"url":"https://github.com/31730/matplotlib/issues/31730"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:843c99da-2713-72b2-61a6-c9a913d304b6 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 85F2:2C3559:D717:11B29:6A52B12B |
| html-safe-nonce | 0f8c1eb4d8c1e08a2fada20ac8a3db19d643df6ada48af00ee3767442a70e766 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NUYyOjJDMzU1OTpENzE3OjExQjI5OjZBNTJCMTJCIiwidmlzaXRvcl9pZCI6IjIxNjE3NjQ1NTM0ODE5NTc2NzUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | d23d9584b4fe808d0ee63b49030e237642285735253526c35722481b614089c9 |
| hovercard-subject-tag | issue:4502724610 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/matplotlib/matplotlib/31730/issue_layout |
| twitter:image | https://opengraph.githubassets.com/35b967452a4ef5f1f5e83af2402c05d70e6c7fc578374f15b54a6d2f52783535/matplotlib/matplotlib/issues/31730 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/35b967452a4ef5f1f5e83af2402c05d70e6c7fc578374f15b54a6d2f52783535/matplotlib/matplotlib/issues/31730 |
| og:image:alt | Bug summary After calling .remove() on the FigureImage object returned by Figure.figimage(...) and then re-attaching it via Figure.add_artist(...), the image is no longer rendered in the saved figu... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | williamlus |
| hostname | github.com |
| expected-hostname | github.com |
| None | b9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb |
| turbo-cache-control | no-preview |
| go-import | github.com/matplotlib/matplotlib git https://github.com/matplotlib/matplotlib.git |
| octolytics-dimension-user_id | 215947 |
| octolytics-dimension-user_login | matplotlib |
| octolytics-dimension-repository_id | 1385122 |
| octolytics-dimension-repository_nwo | matplotlib/matplotlib |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1385122 |
| octolytics-dimension-repository_network_root_nwo | matplotlib/matplotlib |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 07a982c1d40157c619b364352b704c3ce66bb332 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width