I was trying to run the following code at the moment:
imgplot = plt.imshow(dose_data, extent = [0,4,0,6], aspect = 'auto')
On the console, I typed the following input:
In[38]:imgplot
Out[38]: <matplotlib.image.AxesImage at 0x123ebd198>
And the output made me wonder what the object is. After consulting the documentation, it seems like an AxesImage object (AxesImage Documentation). However I was wondering how to use the object stored in imgplot. At the moment I can neither see what it is, nor save it to an image.
P.S. I know how to show an image and how to save an image. I was just wondering how this object could be useful and what it actually is (like, is it an image object? an array? or some other weird type of object?)
As you have already found out, the return type of plt.imshow()
is a matplotlib.image.AxesImage
. The object img
you get when calling img = plt.imshow()
is an instance of that class.
In general, you do not have to care about this object, since it's bound to an axes and most of what you want to do, like showing a figure or saving it, does not require any control over that AxesImage
itself.
Like with any other object, it may be useful for getting access to some of its properties for later use. e.g. img.cmap
returns the colormap of the imgage, img.get_extent()
provides you with the image extent.
There are two applications coming to my mind, where the AxesImage
is frequently used:
img.set_data(data)
plt.colorbar(img, cax=cax)
sets the colorbar of the image img
to the axes cax
.For further details, you would probably need to refine your question, asking more specifically about some property, application, potential use etc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With