On this page
matplotlib.pyplot.imshow
matplotlib.pyplot.imshow(X, cmap=None, norm=None, aspect=None, interpolation=None, alpha=None, vmin=None, vmax=None, origin=None, extent=None, shape=None, filternorm=1, filterrad=4.0, imlim=None, resample=None, url=None, hold=None, data=None, **kwargs)[source]-
Display an image on the axes.
Parameters: -
X : array_like, shape (n, m) or (n, m, 3) or (n, m, 4) -
Display the image in
Xto current axes.Xmay be an array or a PIL image. IfXis an array, it can have the following shapes and types:- MxN -- values to be mapped (float or int)
- MxNx3 -- RGB (float or uint8)
- MxNx4 -- RGBA (float or uint8)
MxN arrays are mapped to colors based on the
norm(mapping scalar to scalar) and thecmap(mapping the normed scalar to a color).Elements of RGB and RGBA arrays represent pixels of an MxN image. All values should be in the range [0 .. 1] for floats or [0 .. 255] for integers. Out-of-range values will be clipped to these bounds.
-
cmap : Colormap, optional, default: None -
If None, default to rc
image.cmapvalue.cmapis ignored ifXis 3-D, directly specifying RGB(A) values. -
aspect : ['auto' | 'equal' | scalar], optional, default: None -
If 'auto', changes the image aspect ratio to match that of the axes.
If 'equal', and
extentis None, changes the axes aspect ratio to match that of the image. Ifextentis notNone, the axes aspect ratio is changed to match that of the extent.If None, default to rc
image.aspectvalue. -
interpolation : string, optional, default: None -
Acceptable values are 'none', 'nearest', 'bilinear', 'bicubic', 'spline16', 'spline36', 'hanning', 'hamming', 'hermite', 'kaiser', 'quadric', 'catrom', 'gaussian', 'bessel', 'mitchell', 'sinc', 'lanczos'
If
interpolationis None, default to rcimage.interpolation. See also thefilternormandfilterradparameters. Ifinterpolationis 'none', then no interpolation is performed on the Agg, ps and pdf backends. Other backends will fall back to 'nearest'. -
norm : Normalize, optional, default: None -
A
Normalizeinstance is used to scale a 2-D floatXinput to the (0, 1) range for input to thecmap. Ifnormis None, use the default func:normalize. Ifnormis an instance ofNoNorm,Xmust be an array of integers that index directly into the lookup table of thecmap. -
vmin, vmax : scalar, optional, default: None -
vminandvmaxare used in conjunction with norm to normalize luminance data. Note if you pass anorminstance, your settings forvminandvmaxwill be ignored. -
alpha : scalar, optional, default: None -
The alpha blending value, between 0 (transparent) and 1 (opaque). The
alphaargument is ignored for RGBA input data. -
origin : ['upper' | 'lower'], optional, default: None -
Place the [0,0] index of the array in the upper left or lower left corner of the axes. If None, default to rc
image.origin. -
extent : scalars (left, right, bottom, top), optional, default: None -
The location, in data-coordinates, of the lower-left and upper-right corners. If
None, the image is positioned such that the pixel centers fall on zero-based (row, column) indices. -
shape : scalars (columns, rows), optional, default: None -
For raw buffer images
-
filternorm : scalar, optional, default: 1 -
A parameter for the antigrain image resize filter. From the antigrain documentation, if
filternorm= 1, the filter normalizes integer values and corrects the rounding errors. It doesn't do anything with the source floating point values, it corrects only integers according to the rule of 1.0 which means that any sum of pixel weights must be equal to 1.0. So, the filter function must produce a graph of the proper shape. -
filterrad : scalar, optional, default: 4.0 -
The filter radius for filters that have a radius parameter, i.e. when interpolation is one of: 'sinc', 'lanczos' or 'blackman'
Returns: -
image : AxesImage
Other Parameters: -
**kwargs : Artist properties.
See also
matshow- Plot a matrix or an array as an image.
Notes
Unless extent is used, pixel centers will be located at integer coordinates. In other words: the origin will coincide with the center of pixel (0, 0).
Two typical representations are used for RGB images with an alpha channel:
- Straight (unassociated) alpha: R, G, and B channels represent the color of the pixel, disregarding its opacity.
- Premultiplied (associated) alpha: R, G, and B channels represent the color of the pixel, adjusted for its opacity by multiplication.
imshowexpects RGB images adopting the straight (unassociated) alpha representation.Note
In addition to the above described arguments, this function can take a data keyword argument. If such a data argument is given, the following arguments are replaced by data[<arg>]:
- All positional and all keyword arguments.
-
Examples using matplotlib.pyplot.imshow
© 2012–2018 Matplotlib Development Team. All rights reserved.
Licensed under the Matplotlib License Agreement.
https://matplotlib.org/2.2.3/api/_as_gen/matplotlib.pyplot.imshow.html