You are reading documentation for the unreleased version of Matplotlib. Try searching for the released version of this page instead?
Version 3.1.0.post1496+gb03370a04
matplotlib
Fork me on GitHub

matplotlib.pyplot.imsave

matplotlib.pyplot.imsave(fname, arr, **kwargs)[source]

Save an array as an image file.

Parameters:
fname : str or PathLike or file-like

A path or a file-like object to store the image in. If format is not set, then the output format is inferred from the extension of fname, if any, and from rcParams["savefig.format"] otherwise. If format is set, it determines the output format.

arr : array-like

The image data. The shape can be one of MxN (luminance), MxNx3 (RGB) or MxNx4 (RGBA).

vmin, vmax : scalar, optional

vmin and vmax set the color scaling for the image by fixing the values that map to the colormap color limits. If either vmin or vmax is None, that limit is determined from the arr min/max value.

cmap : str or Colormap, optional

A Colormap instance or registered colormap name. The colormap maps scalar data to colors. It is ignored for RGB(A) data. Defaults to rcParams["image.cmap"] ('viridis').

format : str, optional

The file format, e.g. 'png', 'pdf', 'svg', ... The behavior when this is unset is documented under fname.

origin : {'upper', 'lower'}, optional

Indicates whether the (0, 0) index of the array is in the upper left or lower left corner of the axes. Defaults to rcParams["image.origin"] ('upper').

dpi : int

The DPI to store in the metadata of the file. This does not affect the resolution of the output image.

metadata : dict, optional

Metadata in the image file. The supported keys depend on the output format, see the documentation of the respective backends for more information.

pil_kwargs : dict, optional

If set to a non-None value, always use Pillow to save the figure (regardless of the output format), and pass these keyword arguments to PIL.Image.save.

If the 'pnginfo' key is present, it completely overrides metadata, including the default 'Software' key.