matplotlib.image
#
The image module supports basic image loading, rescaling and displayoperations.
- classmatplotlib.image.AxesImage(ax,*,cmap=None,norm=None,colorizer=None,interpolation=None,origin=None,extent=None,filternorm=True,filterrad=4.0,resample=False,interpolation_stage=None,**kwargs)[source]#
Bases:
_ImageBase
An image with pixels on a regular grid, attached to an Axes.
- Parameters:
- ax
Axes
The Axes the image will belong to.
- cmapstr or
Colormap
, default:rcParams["image.cmap"]
(default:'viridis'
) The Colormap instance or registered colormap name used to map scalardata to colors.
- normstr or
Normalize
Maps luminance to 0-1.
- interpolationstr, default:
rcParams["image.interpolation"]
(default:'auto'
) Supported values are 'none', 'auto', 'nearest', 'bilinear','bicubic', 'spline16', 'spline36', 'hanning', 'hamming', 'hermite','kaiser', 'quadric', 'catrom', 'gaussian', 'bessel', 'mitchell','sinc', 'lanczos', 'blackman'.
- interpolation_stage{'data', 'rgba'}, default: 'data'
If 'data', interpolationis carried out on the data provided by the user. If 'rgba', theinterpolation is carried out after the colormapping has beenapplied (visual interpolation).
- origin{'upper', 'lower'}, default:
rcParams["image.origin"]
(default:'upper'
) Place the [0, 0] index of the array in the upper left or lower leftcorner of the Axes. The convention 'upper' is typically used formatrices and images.
- extenttuple, optional
The data axes (left, right, bottom, top) for making image plotsregistered with data plots. Default is to label the pixelcenters with the zero-based row and column indices.
- filternormbool, default: True
A parameter for the antigrain image resize filter(see the antigrain documentation).If filternorm is set, the filter normalizes integer values and correctsthe rounding errors. It doesn't do anything with the source floatingpoint values, it corrects only integers according to the rule of 1.0which 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.
- filterradfloat > 0, default: 4
The filter radius for filters that have a radius parameter, i.e. wheninterpolation is one of: 'sinc', 'lanczos' or 'blackman'.
- resamplebool, default: False
When True, use a full resampling method. When False, only resample whenthe output image is larger than the input image.
- **kwargs
Artist
properties
- ax
- Parameters:
- colorizer
colorizer.Colorizer
- colorizer
- get_cursor_data(event)[source]#
Return the image value at the event position orNone if the event isoutside the image.
- get_window_extent(renderer=None)[source]#
Get the artist's bounding box in display space.
The bounding box's width and height are non-negative.
Subclasses should override for inclusion in the bounding box"tight" calculation. Default is to return an empty boundingbox at 0, 0.
Warning
The extent can change due to any changes in the transform stack, suchas changing the Axes limits, the figure size, the canvas used (as isdone when saving a figure), or the DPI.
Relying on a once-retrieved window extent can lead to unexpectedbehavior in various cases such as interactive figures being resized ormoved to a screen with different dpi, or figures that look fine onscreen render incorrectly when saved to file.
To get accurate results you may need to manually call
matplotlib.figure.Figure.savefig
ormatplotlib.figure.Figure.draw_without_rendering
to have Matplotlibcompute the rendered size.
- make_image(renderer,magnification=1.0,unsampled=False)[source]#
Normalize, rescale, and colormap this image's data for rendering usingrenderer, with the givenmagnification.
Ifunsampled is True, the image will not be scaled, but anappropriate affine transformation will be returned instead.
- Returns:
- image(M, N, 4)
numpy.uint8
array The RGBA image, resampled unlessunsampled is True.
- x, yfloat
The upper left corner where the image should be drawn, in pixelspace.
- trans
Affine2D
The affine transformation from image to pixel space.
- image(M, N, 4)
- set(*,agg_filter=<UNSET>,alpha=<UNSET>,animated=<UNSET>,array=<UNSET>,clim=<UNSET>,clip_box=<UNSET>,clip_on=<UNSET>,clip_path=<UNSET>,cmap=<UNSET>,data=<UNSET>,extent=<UNSET>,filternorm=<UNSET>,filterrad=<UNSET>,gid=<UNSET>,in_layout=<UNSET>,interpolation=<UNSET>,interpolation_stage=<UNSET>,label=<UNSET>,mouseover=<UNSET>,norm=<UNSET>,path_effects=<UNSET>,picker=<UNSET>,rasterized=<UNSET>,resample=<UNSET>,sketch_params=<UNSET>,snap=<UNSET>,transform=<UNSET>,url=<UNSET>,visible=<UNSET>,zorder=<UNSET>)[source]#
Set multiple properties at once.
Supported properties are
Property
Description
a filter function, which takes a (m, n, 3) float array and a dpi value, and returns a (m, n, 3) array and two offsets from the bottom left corner of the image
alpha
float or 2D array-like or None
bool
array
array-like
(vmin: float, vmax: float)
BboxBase
or Nonebool
Patch or (Path, Transform) or None
Colormap
or str or Nonedata
array-like or
PIL.Image.Image
4-tuple of float
filternorm
bool
filterrad
positive float
str
bool
interpolation
{'auto', 'nearest', 'bilinear', 'bicubic', 'spline16', 'spline36', 'hanning', 'hamming', 'hermite', 'kaiser', 'quadric', 'catrom', 'gaussian', 'bessel', 'mitchell', 'sinc', 'lanczos', 'none'} or None
interpolation_stage
{'data', 'rgba', 'auto'}, default:
rcParams["image.interpolation_stage"]
(default:'auto'
)object
bool
Normalize
or str or Nonelist of
AbstractPathEffect
None or bool or float or callable
bool
resample
bool, default:
rcParams["image.resample"]
(default:True
)(scale: float, length: float, randomness: float)
bool or None
str
bool
float
- set_extent(extent,**kwargs)[source]#
Set the image extent.
- Parameters:
- extent4-tuple of float
The position and size of the image as tuple
(left,right,bottom,top)
in data coordinates.- **kwargs
Other parameters from which unit info (i.e., thexunits,yunits,zunits (for 3D Axes),runits andthetaunits (forpolar Axes) entries are applied, if present.
Notes
This updates
Axes.dataLim
, and, if autoscaling, setsAxes.viewLim
to tightly fit the image, regardless ofdataLim
. Autoscalingstate is not changed, so a subsequent call toAxes.autoscale_view
will redo the autoscaling in accord withdataLim
.
- classmatplotlib.image.BboxImage(bbox,*,cmap=None,norm=None,colorizer=None,interpolation=None,origin=None,filternorm=True,filterrad=4.0,resample=False,**kwargs)[source]#
Bases:
_ImageBase
The Image class whose size is determined by the given bbox.
- Parameters:
- bboxBboxBase or Callable[RendererBase, BboxBase]
The bbox or a function to generate the bbox
Warning
If using
matplotlib.artist.Artist.get_window_extent
as thecallable ensure that the other artist is drawn first (lower zorder)or you may need to renderer the figure twice to ensure that thecomputed bbox is accurate.- cmapstr or
Colormap
, default:rcParams["image.cmap"]
(default:'viridis'
) The Colormap instance or registered colormap name used to map scalardata to colors.
- normstr or
Normalize
Maps luminance to 0-1.
- interpolationstr, default:
rcParams["image.interpolation"]
(default:'auto'
) Supported values are 'none', 'auto', 'nearest', 'bilinear','bicubic', 'spline16', 'spline36', 'hanning', 'hamming', 'hermite','kaiser', 'quadric', 'catrom', 'gaussian', 'bessel', 'mitchell','sinc', 'lanczos', 'blackman'.
- origin{'upper', 'lower'}, default:
rcParams["image.origin"]
(default:'upper'
) Place the [0, 0] index of the array in the upper left or lower leftcorner of the Axes. The convention 'upper' is typically used formatrices and images.
- filternormbool, default: True
A parameter for the antigrain image resize filter(see the antigrain documentation).If filternorm is set, the filter normalizes integer values and correctsthe rounding errors. It doesn't do anything with the source floatingpoint values, it corrects only integers according to the rule of 1.0which 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.
- filterradfloat > 0, default: 4
The filter radius for filters that have a radius parameter, i.e. wheninterpolation is one of: 'sinc', 'lanczos' or 'blackman'.
- resamplebool, default: False
When True, use a full resampling method. When False, only resample whenthe output image is larger than the input image.
- **kwargs
Artist
properties
- Parameters:
- colorizer
colorizer.Colorizer
- colorizer
- get_window_extent(renderer=None)[source]#
Get the artist's bounding box in display space.
The bounding box's width and height are non-negative.
Subclasses should override for inclusion in the bounding box"tight" calculation. Default is to return an empty boundingbox at 0, 0.
Warning
The extent can change due to any changes in the transform stack, suchas changing the Axes limits, the figure size, the canvas used (as isdone when saving a figure), or the DPI.
Relying on a once-retrieved window extent can lead to unexpectedbehavior in various cases such as interactive figures being resized ormoved to a screen with different dpi, or figures that look fine onscreen render incorrectly when saved to file.
To get accurate results you may need to manually call
matplotlib.figure.Figure.savefig
ormatplotlib.figure.Figure.draw_without_rendering
to have Matplotlibcompute the rendered size.
- make_image(renderer,magnification=1.0,unsampled=False)[source]#
Normalize, rescale, and colormap this image's data for rendering usingrenderer, with the givenmagnification.
Ifunsampled is True, the image will not be scaled, but anappropriate affine transformation will be returned instead.
- Returns:
- image(M, N, 4)
numpy.uint8
array The RGBA image, resampled unlessunsampled is True.
- x, yfloat
The upper left corner where the image should be drawn, in pixelspace.
- trans
Affine2D
The affine transformation from image to pixel space.
- image(M, N, 4)
- set(*,agg_filter=<UNSET>,alpha=<UNSET>,animated=<UNSET>,array=<UNSET>,clim=<UNSET>,clip_box=<UNSET>,clip_on=<UNSET>,clip_path=<UNSET>,cmap=<UNSET>,data=<UNSET>,filternorm=<UNSET>,filterrad=<UNSET>,gid=<UNSET>,in_layout=<UNSET>,interpolation=<UNSET>,interpolation_stage=<UNSET>,label=<UNSET>,mouseover=<UNSET>,norm=<UNSET>,path_effects=<UNSET>,picker=<UNSET>,rasterized=<UNSET>,resample=<UNSET>,sketch_params=<UNSET>,snap=<UNSET>,transform=<UNSET>,url=<UNSET>,visible=<UNSET>,zorder=<UNSET>)[source]#
Set multiple properties at once.
Supported properties are
Property
Description
a filter function, which takes a (m, n, 3) float array and a dpi value, and returns a (m, n, 3) array and two offsets from the bottom left corner of the image
alpha
float or 2D array-like or None
bool
array
array-like
(vmin: float, vmax: float)
BboxBase
or Nonebool
Patch or (Path, Transform) or None
Colormap
or str or Nonedata
array-like or
PIL.Image.Image
filternorm
bool
filterrad
positive float
str
bool
interpolation
{'auto', 'nearest', 'bilinear', 'bicubic', 'spline16', 'spline36', 'hanning', 'hamming', 'hermite', 'kaiser', 'quadric', 'catrom', 'gaussian', 'bessel', 'mitchell', 'sinc', 'lanczos', 'none'} or None
interpolation_stage
{'data', 'rgba', 'auto'}, default:
rcParams["image.interpolation_stage"]
(default:'auto'
)object
bool
Normalize
or str or Nonelist of
AbstractPathEffect
None or bool or float or callable
bool
resample
bool, default:
rcParams["image.resample"]
(default:True
)(scale: float, length: float, randomness: float)
bool or None
str
bool
float
- classmatplotlib.image.FigureImage(fig,*,cmap=None,norm=None,colorizer=None,offsetx=0,offsety=0,origin=None,**kwargs)[source]#
Bases:
_ImageBase
An image attached to a figure.
cmap is a colors.Colormap instancenorm is a colors.Normalize instance to map luminance to 0-1
kwargs are an optional list of Artist keyword args
- make_image(renderer,magnification=1.0,unsampled=False)[source]#
Normalize, rescale, and colormap this image's data for rendering usingrenderer, with the givenmagnification.
Ifunsampled is True, the image will not be scaled, but anappropriate affine transformation will be returned instead.
- Returns:
- image(M, N, 4)
numpy.uint8
array The RGBA image, resampled unlessunsampled is True.
- x, yfloat
The upper left corner where the image should be drawn, in pixelspace.
- trans
Affine2D
The affine transformation from image to pixel space.
- image(M, N, 4)
- set(*,agg_filter=<UNSET>,alpha=<UNSET>,animated=<UNSET>,array=<UNSET>,clim=<UNSET>,clip_box=<UNSET>,clip_on=<UNSET>,clip_path=<UNSET>,cmap=<UNSET>,data=<UNSET>,filternorm=<UNSET>,filterrad=<UNSET>,gid=<UNSET>,in_layout=<UNSET>,interpolation=<UNSET>,interpolation_stage=<UNSET>,label=<UNSET>,mouseover=<UNSET>,norm=<UNSET>,path_effects=<UNSET>,picker=<UNSET>,rasterized=<UNSET>,resample=<UNSET>,sketch_params=<UNSET>,snap=<UNSET>,transform=<UNSET>,url=<UNSET>,visible=<UNSET>,zorder=<UNSET>)[source]#
Set multiple properties at once.
Supported properties are
Property
Description
a filter function, which takes a (m, n, 3) float array and a dpi value, and returns a (m, n, 3) array and two offsets from the bottom left corner of the image
alpha
float or 2D array-like or None
bool
array
array-like
(vmin: float, vmax: float)
BboxBase
or Nonebool
Patch or (Path, Transform) or None
Colormap
or str or Noneunknown
filternorm
bool
filterrad
positive float
str
bool
interpolation
{'auto', 'nearest', 'bilinear', 'bicubic', 'spline16', 'spline36', 'hanning', 'hamming', 'hermite', 'kaiser', 'quadric', 'catrom', 'gaussian', 'bessel', 'mitchell', 'sinc', 'lanczos', 'none'} or None
interpolation_stage
{'data', 'rgba', 'auto'}, default:
rcParams["image.interpolation_stage"]
(default:'auto'
)object
bool
Normalize
or str or Nonelist of
AbstractPathEffect
None or bool or float or callable
bool
resample
bool, default:
rcParams["image.resample"]
(default:True
)(scale: float, length: float, randomness: float)
bool or None
str
bool
float
- zorder=0#
- classmatplotlib.image.NonUniformImage(ax,*,interpolation='nearest',**kwargs)[source]#
Bases:
AxesImage
An image with pixels on a rectilinear grid.
In contrast to
AxesImage
, where pixels are on a regular grid,NonUniformImage allows rows and columns with individual heights / widths.See alsoImage nonuniform.
- Parameters:
- get_cursor_data(event)[source]#
Return the image value at the event position orNone if the event isoutside the image.
- make_image(renderer,magnification=1.0,unsampled=False)[source]#
Normalize, rescale, and colormap this image's data for rendering usingrenderer, with the givenmagnification.
Ifunsampled is True, the image will not be scaled, but anappropriate affine transformation will be returned instead.
- Returns:
- image(M, N, 4)
numpy.uint8
array The RGBA image, resampled unlessunsampled is True.
- x, yfloat
The upper left corner where the image should be drawn, in pixelspace.
- trans
Affine2D
The affine transformation from image to pixel space.
- image(M, N, 4)
- set(*,agg_filter=<UNSET>,alpha=<UNSET>,animated=<UNSET>,array=<UNSET>,clim=<UNSET>,clip_box=<UNSET>,clip_on=<UNSET>,clip_path=<UNSET>,cmap=<UNSET>,data=<UNSET>,extent=<UNSET>,filternorm=<UNSET>,filterrad=<UNSET>,gid=<UNSET>,in_layout=<UNSET>,interpolation=<UNSET>,interpolation_stage=<UNSET>,label=<UNSET>,mouseover=<UNSET>,norm=<UNSET>,path_effects=<UNSET>,picker=<UNSET>,rasterized=<UNSET>,resample=<UNSET>,sketch_params=<UNSET>,snap=<UNSET>,transform=<UNSET>,url=<UNSET>,visible=<UNSET>,zorder=<UNSET>)[source]#
Set multiple properties at once.
Supported properties are
Property
Description
a filter function, which takes a (m, n, 3) float array and a dpi value, and returns a (m, n, 3) array and two offsets from the bottom left corner of the image
alpha
float or 2D array-like or None
bool
array
unknown
(vmin: float, vmax: float)
BboxBase
or Nonebool
Patch or (Path, Transform) or None
unknown
unknown
4-tuple of float
filternorm
unknown
filterrad
unknown
str
bool
{'nearest', 'bilinear'} or None
interpolation_stage
{'data', 'rgba', 'auto'}, default:
rcParams["image.interpolation_stage"]
(default:'auto'
)object
bool
unknown
list of
AbstractPathEffect
None or bool or float or callable
bool
resample
bool, default:
rcParams["image.resample"]
(default:True
)(scale: float, length: float, randomness: float)
bool or None
str
bool
float
- set_array(*args)[source]#
Retained for backwards compatibility - use set_data instead.
- Parameters:
- Aarray-like
- set_data(x,y,A)[source]#
Set the grid for the pixel centers, and the pixel values.
- Parameters:
- x, y1D array-like
Monotonic arrays of shapes (N,) and (M,), respectively, specifyingpixel centers.
- Aarray-like
(M, N)
ndarray
or masked array of values to becolormapped, or (M, N, 3) RGB array, or (M, N, 4) RGBA array.
- set_filternorm(filternorm)[source]#
Set whether the resize filter normalizes the weights.
See help for
imshow
.- Parameters:
- filternormbool
- set_filterrad(filterrad)[source]#
Set the resize filter radius (only applicable to someinterpolation schemes).
See help for
imshow
.- Parameters:
- filterradpositive float
- set_interpolation(s)[source]#
- Parameters:
- s{'nearest', 'bilinear'} or None
If None, use
rcParams["image.interpolation"]
(default:'auto'
).
- classmatplotlib.image.PcolorImage(ax,x=None,y=None,A=None,*,cmap=None,norm=None,colorizer=None,**kwargs)[source]#
Bases:
AxesImage
Make a pcolor-style plot with an irregular rectangular grid.
This uses a variation of the original irregular image code,and it is used by pcolorfast for the corresponding grid type.
- Parameters:
- ax
Axes
The Axes the image will belong to.
- x, y1D array-like, optional
Monotonic arrays of length N+1 and M+1, respectively, specifyingrectangle boundaries. If not given, will default to
range(N+1)
andrange(M+1)
, respectively.- Aarray-like
The data to be color-coded. The interpretation depends on theshape:
(M, N)
ndarray
or masked array: values to be colormapped(M, N, 3): RGB array
(M, N, 4): RGBA array
- cmapstr or
Colormap
, default:rcParams["image.cmap"]
(default:'viridis'
) The Colormap instance or registered colormap name used to mapscalar data to colors.
- normstr or
Normalize
Maps luminance to 0-1.
- **kwargs
Artist
properties
- ax
- get_cursor_data(event)[source]#
Return the image value at the event position orNone if the event isoutside the image.
- make_image(renderer,magnification=1.0,unsampled=False)[source]#
Normalize, rescale, and colormap this image's data for rendering usingrenderer, with the givenmagnification.
Ifunsampled is True, the image will not be scaled, but anappropriate affine transformation will be returned instead.
- Returns:
- image(M, N, 4)
numpy.uint8
array The RGBA image, resampled unlessunsampled is True.
- x, yfloat
The upper left corner where the image should be drawn, in pixelspace.
- trans
Affine2D
The affine transformation from image to pixel space.
- image(M, N, 4)
- set(*,agg_filter=<UNSET>,alpha=<UNSET>,animated=<UNSET>,array=<UNSET>,clim=<UNSET>,clip_box=<UNSET>,clip_on=<UNSET>,clip_path=<UNSET>,cmap=<UNSET>,data=<UNSET>,extent=<UNSET>,filternorm=<UNSET>,filterrad=<UNSET>,gid=<UNSET>,in_layout=<UNSET>,interpolation=<UNSET>,interpolation_stage=<UNSET>,label=<UNSET>,mouseover=<UNSET>,norm=<UNSET>,path_effects=<UNSET>,picker=<UNSET>,rasterized=<UNSET>,resample=<UNSET>,sketch_params=<UNSET>,snap=<UNSET>,transform=<UNSET>,url=<UNSET>,visible=<UNSET>,zorder=<UNSET>)[source]#
Set multiple properties at once.
Supported properties are
Property
Description
a filter function, which takes a (m, n, 3) float array and a dpi value, and returns a (m, n, 3) array and two offsets from the bottom left corner of the image
alpha
float or 2D array-like or None
bool
array
unknown
(vmin: float, vmax: float)
BboxBase
or Nonebool
Patch or (Path, Transform) or None
Colormap
or str or Noneunknown
4-tuple of float
filternorm
bool
filterrad
positive float
str
bool
interpolation
{'auto', 'nearest', 'bilinear', 'bicubic', 'spline16', 'spline36', 'hanning', 'hamming', 'hermite', 'kaiser', 'quadric', 'catrom', 'gaussian', 'bessel', 'mitchell', 'sinc', 'lanczos', 'none'} or None
interpolation_stage
{'data', 'rgba', 'auto'}, default:
rcParams["image.interpolation_stage"]
(default:'auto'
)object
bool
Normalize
or str or Nonelist of
AbstractPathEffect
None or bool or float or callable
bool
resample
bool, default:
rcParams["image.resample"]
(default:True
)(scale: float, length: float, randomness: float)
bool or None
str
bool
float
- set_array(*args)[source]#
Retained for backwards compatibility - use set_data instead.
- Parameters:
- Aarray-like
- set_data(x,y,A)[source]#
Set the grid for the rectangle boundaries, and the data values.
- Parameters:
- x, y1D array-like, optional
Monotonic arrays of length N+1 and M+1, respectively, specifyingrectangle boundaries. If not given, will default to
range(N+1)
andrange(M+1)
, respectively.- Aarray-like
The data to be color-coded. The interpretation depends on theshape:
(M, N)
ndarray
or masked array: values to be colormapped(M, N, 3): RGB array
(M, N, 4): RGBA array
- matplotlib.image.composite_images(images,renderer,magnification=1.0)[source]#
Composite a number of RGBA images into one. The images arecomposited in the order in which they appear in theimages list.
- Parameters:
- imageslist of Images
Each must have a
make_image
method. For each image,can_composite
should returnTrue
, though this is notenforced by this function. Each image must have a purelyaffine transformation with no shear.- renderer
RendererBase
- magnificationfloat, default: 1
The additional magnification to apply for the renderer in use.
- Returns:
- image(M, N, 4)
numpy.uint8
array The composited RGBA image.
- offset_x, offset_yfloat
The (left, bottom) offset where the composited image should be placedin the output figure.
- image(M, N, 4)
- matplotlib.image.imread(fname,format=None)[source]#
Read an image from a file into an array.
Note
This function exists for historical reasons. It is recommended touse
PIL.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. with
np.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 by
PIL.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.
- matplotlib.image.imsave(fname,arr,vmin=None,vmax=None,cmap=None,format=None,origin=None,dpi=100,*,metadata=None,pil_kwargs=None)[source]#
Colormap and save an array as an image file.
RGB(A) images are passed through. Single channel images will becolormapped according tocmap andnorm.
Note
If you want to save a single channel image as gray scale please use animage I/O library (such as pillow, tifffile, or imageio) directly.
- Parameters:
- fnamestr or path-like or file-like
A path or a file-like object to store the image in.Ifformat is not set, then the output format is inferred from theextension offname, if any, and from
rcParams["savefig.format"]
(default:'png'
) otherwise.Ifformat is set, it determines the output format.- arrarray-like
The image data. Accepts NumPy arrays or sequences(e.g., lists or tuples). The shape can be one ofMxN (luminance), MxNx3 (RGB) or MxNx4 (RGBA).
- vmin, vmaxfloat, optional
vmin andvmax set the color scaling for the image by fixing thevalues that map to the colormap color limits. If eithervminorvmax is None, that limit is determined from thearrmin/max value.
- cmapstr or
Colormap
, default:rcParams["image.cmap"]
(default:'viridis'
) A Colormap instance or registered colormap name. The colormapmaps scalar data to colors. It is ignored for RGB(A) data.
- formatstr, optional
The file format, e.g. 'png', 'pdf', 'svg', ... The behavior when thisis unset is documented underfname.
- origin{'upper', 'lower'}, default:
rcParams["image.origin"]
(default:'upper'
) Indicates whether the
(0,0)
index of the array is in the upperleft or lower left corner of the Axes.- dpifloat
The DPI to store in the metadata of the file. This does not affect theresolution of the output image. Depending on file format, this may berounded to the nearest integer.
- metadatadict, optional
Metadata in the image file. The supported keys depend on the outputformat, see the documentation of the respective backends for moreinformation.Currently only supported for "png", "pdf", "ps", "eps", and "svg".
- pil_kwargsdict, optional
Keyword arguments passed to
PIL.Image.Image.save
. If the 'pnginfo'key is present, it completely overridesmetadata, including thedefault 'Software' key.
- matplotlib.image.pil_to_array(pilImage)[source]#
Load aPIL image and return it as a numpy int array.
- Returns:
- numpy.array
The array shape depends on the image type:
(M, N) for grayscale images.
(M, N, 3) for RGB images.
(M, N, 4) for RGBA images.
- matplotlib.image.thumbnail(infile,thumbfile,scale=0.1,interpolation='bilinear',preview=False)[source]#
Make a thumbnail of image ininfile with output filenamethumbfile.
SeeImage thumbnail.
- Parameters:
- infilestr or file-like
The image file. Matplotlib relies onPillow for image reading, andthus supports a wide range of file formats, including PNG, JPG, TIFFand others.
- thumbfilestr or file-like
The thumbnail filename.
- scalefloat, default: 0.1
The scale factor for the thumbnail.
- interpolationstr, default: 'bilinear'
The interpolation scheme used in the resampling. See theinterpolation parameter of
imshow
for possible values.- previewbool, default: False
If True, the default backend (presumably a user interfacebackend) will be used which will cause a figure to be raised if
show
is called. If it is False, the figure iscreated usingFigureCanvasBase
and the drawing backend is selectedasFigure.savefig
would normally do.
- Returns:
Figure
The figure instance containing the thumbnail.