matplotlib.pyplot.imsave#
- matplotlib.pyplot.imsave(fname,arr,**kwargs)[source]#
Colormap and save an array as an image file.
RGB(A) images are passed through. Single channel images will becolormapped according tocmap andnorm.
Note
If you want to save a single channel image as gray scale please use animage I/O library (such as pillow, tifffile, or imageio) directly.
- Parameters:
- fnamestr or path-like or file-like
A path or a file-like object to store the image in.Ifformat is not set, then the output format is inferred from theextension offname, if any, and from
rcParams["savefig.format"]
(default:'png'
) otherwise.Ifformat is set, it determines the output format.- arrarray-like
The image data. Accepts NumPy arrays or sequences(e.g., lists or tuples). The shape can be one ofMxN (luminance), MxNx3 (RGB) or MxNx4 (RGBA).
- vmin, vmaxfloat, optional
vmin andvmax set the color scaling for the image by fixing thevalues that map to the colormap color limits. If eithervminorvmax is None, that limit is determined from thearrmin/max value.
- cmapstr or
Colormap
, default:rcParams["image.cmap"]
(default:'viridis'
) A Colormap instance or registered colormap name. The colormapmaps scalar data to colors. It is ignored for RGB(A) data.
- formatstr, optional
The file format, e.g. 'png', 'pdf', 'svg', ... The behavior when thisis unset is documented underfname.
- origin{'upper', 'lower'}, default:
rcParams["image.origin"]
(default:'upper'
) Indicates whether the
(0,0)
index of the array is in the upperleft or lower left corner of the Axes.- dpifloat
The DPI to store in the metadata of the file. This does not affect theresolution of the output image. Depending on file format, this may berounded to the nearest integer.
- metadatadict, optional
Metadata in the image file. The supported keys depend on the outputformat, see the documentation of the respective backends for moreinformation.Currently only supported for "png", "pdf", "ps", "eps", and "svg".
- pil_kwargsdict, optional
Keyword arguments passed to
PIL.Image.Image.save
. If the 'pnginfo'key is present, it completely overridesmetadata, including thedefault 'Software' key.
Notes
Note
This is equivalent to
matplotlib.image.imsave
.