matplotlib.pyplot.imread#

matplotlib.pyplot.imread(fname,format=None)[source]#

Read an image from a file into an array.

Note

This function exists for historical reasons. It is recommended tousePIL.Image.open instead for loading images.

Parameters:
fnamestr or file-like

The image file to read: a filename, a URL or a file-like object openedin read-binary mode.

Passing a URL is deprecated. Please open the URLfor reading and pass the result to Pillow, e.g. withnp.array(PIL.Image.open(urllib.request.urlopen(url))).

formatstr, optional

The image file format assumed for reading the data. The image isloaded as a PNG file ifformat is set to "png", iffname is a pathor opened file with a ".png" extension, or if it is a URL. In allother cases,format is ignored and the format is auto-detected byPIL.Image.open.

Returns:
numpy.array

The image data. The returned array has shape

  • (M, N) for grayscale images.

  • (M, N, 3) for RGB images.

  • (M, N, 4) for RGBA images.

PNG images are returned as float arrays (0-1). All other formats arereturned as int arrays, with a bit depth determined by the file'scontents.

Notes

Note

This is equivalent tomatplotlib.image.imread.

Examples usingmatplotlib.pyplot.imread#

Clipping images with patches

Clipping images with patches

Many ways to plot images

Many ways to plot images

Watermark image

Watermark image

Ribbon box

Ribbon box

Using a text as a Path

Using a text as a Path

Convert texts to images

Convert texts to images

mplcvd -- an example of figure hook

mplcvd -- an example of figure hook