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 correctly for a Text artist created via Figure.text(...), suggesting figimage objects are not properly handled by Figure.add_artist.
Code for reproduction
import matplotlib.pyplot as plt
from matplotlib.figure import Figure
from io import BytesIO
def text_to_rgba(s, *, dpi, **kwargs):
fig = Figure(facecolor="none")
fig.text(0, 0, s, **kwargs)
with BytesIO() as buf:
fig.savefig(buf, dpi=dpi, format="png", bbox_inches="tight",
pad_inches=0)
buf.seek(0)
rgba = plt.imread(buf)
return rgba
# --- Case 1: figimage ---
fig, ax = plt.subplots()
rgba1 = text_to_rgba(r"IQ: $\sigma_i=15$", color="blue", fontsize=10, dpi=200)
figimg = fig.figimage(rgba1, 100, 50)
plt.savefig("figimage_before.png") # image visible (correct)
figimg.remove()
fig.add_artist(figimg)
plt.savefig("figimage_after.png") # image MISSING (bug)
# --- Case 2: text (control) ---
fig, ax = plt.subplots()
mytext = fig.text(0.2, 0.15, r"IQ: $\sigma_i=15$", color="blue", fontsize=20)
plt.savefig("text_before.png") # text visible (correct)
mytext.remove()
fig.add_artist(mytext)
plt.savefig("text_after.png") # text visible (correct)
Actual outcome
figimage_before.png
figimage_after.png
Expected outcome
figimage_before.png
figimage_after.png
Additional information
No response
Operating system
No response
Matplotlib Version
0.2.0.dev54524+unknown.ga94275af4
Matplotlib Backend
No response
Python version
No response
Jupyter version
No response
Installation
None
Bug summary
After calling
.remove()on theFigureImageobject returned byFigure.figimage(...)and then re-attaching it viaFigure.add_artist(...), the image is no longer rendered in the saved figure. The same remove/re-add cycle works correctly for aTextartist created viaFigure.text(...), suggestingfigimageobjects are not properly handled byFigure.add_artist.Code for reproduction
Actual outcome
figimage_before.png
figimage_after.png
Expected outcome
figimage_before.png
figimage_after.png
Additional information
No response
Operating system
No response
Matplotlib Version
0.2.0.dev54524+unknown.ga94275af4
Matplotlib Backend
No response
Python version
No response
Jupyter version
No response
Installation
None