Colormap and save an array as an image file. RGB(A) images are passed through. Single channel images will be colormapped according to *cmap* and *norm*. .. note:: If you want to save a single channel image as gray scale please use an image I/O library (such as pill
(fname, arr, vmin=None, vmax=None, cmap=None, format=None,
origin=None, dpi=100, *, metadata=None, pil_kwargs=None)
| 1591 | |
| 1592 | |
| 1593 | def imsave(fname, arr, vmin=None, vmax=None, cmap=None, format=None, |
| 1594 | origin=None, dpi=100, *, metadata=None, pil_kwargs=None): |
| 1595 | """ |
| 1596 | Colormap and save an array as an image file. |
| 1597 | |
| 1598 | RGB(A) images are passed through. Single channel images will be |
| 1599 | colormapped according to *cmap* and *norm*. |
| 1600 | |
| 1601 | .. note:: |
| 1602 | |
| 1603 | If you want to save a single channel image as gray scale please use an |
| 1604 | image I/O library (such as pillow, tifffile, or imageio) directly. |
| 1605 | |
| 1606 | Parameters |
| 1607 | ---------- |
| 1608 | fname : str or path-like or file-like |
| 1609 | A path or a file-like object to store the image in. |
| 1610 | If *format* is not set, then the output format is inferred from the |
| 1611 | extension of *fname*, if any, and from :rc:`savefig.format` otherwise. |
| 1612 | If *format* is set, it determines the output format. |
| 1613 | arr : array-like |
| 1614 | The image data. Accepts NumPy arrays or sequences |
| 1615 | (e.g., lists or tuples). The shape can be one of |
| 1616 | MxN (luminance), MxNx3 (RGB) or MxNx4 (RGBA). |
| 1617 | vmin, vmax : float, optional |
| 1618 | *vmin* and *vmax* set the color scaling for the image by fixing the |
| 1619 | values that map to the colormap color limits. If either *vmin* |
| 1620 | or *vmax* is None, that limit is determined from the *arr* |
| 1621 | min/max value. |
| 1622 | cmap : str or `~matplotlib.colors.Colormap`, default: :rc:`image.cmap` |
| 1623 | A Colormap instance or registered colormap name. The colormap |
| 1624 | maps scalar data to colors. It is ignored for RGB(A) data. |
| 1625 | format : str, optional |
| 1626 | The file format, e.g. 'png', 'pdf', 'svg', ... The behavior when this |
| 1627 | is unset is documented under *fname*. |
| 1628 | origin : {'upper', 'lower'}, default: :rc:`image.origin` |
| 1629 | Indicates whether the ``(0, 0)`` index of the array is in the upper |
| 1630 | left or lower left corner of the Axes. |
| 1631 | dpi : float |
| 1632 | The DPI to store in the metadata of the file. This does not affect the |
| 1633 | resolution of the output image. Depending on file format, this may be |
| 1634 | rounded to the nearest integer. |
| 1635 | metadata : dict, optional |
| 1636 | Metadata in the image file. The supported keys depend on the output |
| 1637 | format, see the documentation of the respective backends for more |
| 1638 | information. |
| 1639 | Currently only supported for "png", "pdf", "ps", "eps", and "svg". |
| 1640 | pil_kwargs : dict, optional |
| 1641 | Keyword arguments passed to `PIL.Image.Image.save`. If the 'pnginfo' |
| 1642 | key is present, it completely overrides *metadata*, including the |
| 1643 | default 'Software' key. |
| 1644 | """ |
| 1645 | from matplotlib.figure import Figure |
| 1646 | |
| 1647 | # Normalizing input (e.g., list or tuples) to NumPy array if needed |
| 1648 | arr = np.asanyarray(arr) |
| 1649 | |
| 1650 | if isinstance(fname, os.PathLike): |
nothing calls this directly
no test coverage detected
searching dependent graphs…