You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It appears a transform is sometimes applied to the image and sometimes not.
Code for reproduction
frommatplotlibimportpyplotplt=pyplotimportnumpyasnpfig=pyplot.figure()
ax=fig.subplots()
fig_bbox=fig.bboxwidth, height=fig_bbox.width, fig_bbox.heightimg=np.zeros((int(height), int(width), 3))
img+= (127, 0, 0)
fig.figimage(img, 0, 0, zorder=-1)
# show the figure, image is not scaled as I would expectplt.show()
# save as a png, image is scaled as I would expectfig.savefig('foo.png')
# save as an svg, image matches the one in the FigureCanvas window.fig.savefig('foo.svg')
# NB reversing the order of the two savefig calls produces images# matching the FigureCanvas version.
Actual outcome
Expected outcome
I would expect all images to look like the png image, i.e. scaled to the figure size.
Including resize=True in the call to figimage doesn't seem to change the behaviour.
I am looking for is a reliable way to put a patch of color on the figure -- in my actual code I am not looking for a patch that covers the whole figure, this is just toy code to demonstrate the issue.
it wouldn't surprise me if figimage has fallen out of repair. I guess someone could fix it, but I'm not a particular fan of the API.
If you just want a patch, then just use Patch, and set the transform to fig.transFig. If you want a background image, I'd just make an axes that fills the whole figure (fig.add_axes([0, 0, 1, 1])).
Thanks very much for this, most helpful.
I've gone with adding a background axes that fills the whole figure and it seems to be working nicely.
Inclined to agree re: figimage API, given the dpi issue.
@jklymak I'm also having issues with figimage. Do you still plan to deprecate it? Perhaps it's worth adding a warning + the recommended alternative to the documentation for figimage.
Activity
jklymak commentedon Jul 8, 2022
The dpi changes during the lifetime of the figure, so its not surprising that the image changes size. Did you want the
resize=Trueoption? https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.figimage.htmlswfiua commentedon Jul 8, 2022
Thanks, I hadn't considered dpi changes.
Including resize=True in the call to figimage doesn't seem to change the behaviour.
I am looking for is a reliable way to put a patch of color on the figure -- in my actual code I am not looking for a patch that covers the whole figure, this is just toy code to demonstrate the issue.
jklymak commentedon Jul 8, 2022
it wouldn't surprise me if figimage has fallen out of repair. I guess someone could fix it, but I'm not a particular fan of the API.
If you just want a patch, then just use Patch, and set the transform to fig.transFig. If you want a background image, I'd just make an axes that fills the whole figure (
fig.add_axes([0, 0, 1, 1])).swfiua commentedon Jul 8, 2022
Thanks very much for this, most helpful.
I've gone with adding a background axes that fills the whole figure and it seems to be working nicely.
Inclined to agree re: figimage API, given the dpi issue.
jklymak commentedon Jul 8, 2022
I think we can re-open. Either the action item is to deprecate figimage or to fix it so at least the resize option works.
carlosgmartin commentedon Feb 17, 2025
@jklymak I'm also having issues with
figimage. Do you still plan to deprecate it? Perhaps it's worth adding a warning + the recommended alternative to the documentation forfigimage.