You are reading an old version of the documentation (v3.0.2). For the latest version see
Version 3.0.2
Fork me on GitHub


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

Save an array as in image file.

The output formats available depend on the backend being used.

fname : str or file-like

The filename or a Python file-like object to store the image in. The necessary output format is inferred from the filename extension but may be explicitly overwritten using 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', ... . If not given, the format is deduced form the filename extension in fname. See Figure.savefig for details.

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.