| [ Web Proxy ] |
| Viewing: https://matplotlib.org/stable/api/_as_gen/../toolkits/../image_api.html | [Back] [Original] |
matplotlib.image#The image module supports basic image loading, rescaling and display operations.
Bases: _ImageBase
An image with pixels on a regular grid, attached to an Axes.
AxesThe Axes the image will belong to.
Colormap, default: rcParams["image.cmap"] (default: 'viridis')The Colormap instance or registered colormap name used to map scalar data to colors.
NormalizeMaps luminance to 0-1.
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'.
If 'data', interpolation is carried out on the data provided by the user. If 'rgba', the interpolation is carried out after the colormapping has been applied (visual interpolation).
rcParams["image.origin"] (default: 'upper')Place the [0, 0] index of the array in the upper left or lower left corner of the Axes. The convention 'upper' is typically used for matrices and images.
The data axes (left, right, bottom, top) for making image plots registered with data plots. Default is to label the pixel centers with the zero-based row and column indices.
A parameter for the antigrain image resize filter (see the antigrain documentation). If filternorm is set, 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.
The filter radius for filters that have a radius parameter, i.e. when interpolation is one of: 'sinc', 'lanczos' or 'blackman'.
When True, use a full resampling method. When False, only resample when the output image is larger than the input image.
Artist propertiescolorizer.ColorizerReturn the image value at the event position or None if the event is outside the image.
Get the artist's bounding box in display space, ignoring clipping.
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 bounding box at 0, 0.
Warning
The extent can change due to any changes in the transform stack, such as changing the Axes limits, the figure size, the canvas used (as is done when saving a figure), or the DPI.
Relying on a once-retrieved window extent can lead to unexpected behavior in various cases such as interactive figures being resized or moved to a screen with different dpi, or figures that look fine on screen render incorrectly when saved to file.
To get accurate results you may need to manually call
savefig or draw_without_rendering to have
Matplotlib compute the rendered size.
RendererBase, optionalRenderer used to draw the figure (i.e. fig.canvas.get_renderer()).
See also
Artist.get_tightbboxGet the artist bounding box, taking clipping into account.
Normalize, rescale, and colormap this image's data for rendering using renderer, with the given magnification.
If unsampled is True, the image will not be scaled, but an appropriate affine transformation will be returned instead.
numpy.uint8 arrayThe RGBA image, resampled unless unsampled is True.
The upper left corner where the image should be drawn, in pixel space.
Affine2DThe affine transformation from image to pixel space.
Set multiple properties at once.
a.set(a=A, b=B, c=C)
is equivalent to
a.set_a(A)
a.set_b(B)
a.set_c(C)
In addition to the full property names, aliases are also supported, e.g.
set(lw=2) is equivalent to set(linewidth=2), but it is an error
to pass both simultaneously.
The order of the individual setter calls matches the order of parameters
in set(). However, most properties do not depend on each other so
that order is rarely relevant.
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
alphafloat or 2D array-like or None
bool
arrayarray-like
(vmin: float, vmax: float)
BboxBaseor Nonebool
Patch or (Path, Transform) or None
Colormapor str or None
dataarray-like or
PIL.Image.Image4-tuple of float
filternormbool
filterradpositive 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
Normalizeor str or Nonelist of
AbstractPathEffectNone or bool or float or callable
bool
resamplebool, default:
rcParams["image.resample"](default:True)(scale: float, length: float, randomness: float)
bool or None
str
bool
float
Set the image extent.
The position and size of the image as tuple
(left, right, bottom, top) in data coordinates.
Other parameters from which unit info (i.e., the xunits, yunits, zunits (for 3D Axes), runits and thetaunits (for polar Axes) entries are applied, if present.
Notes
This updates Axes.dataLim, and, if autoscaling, sets Axes.viewLim
to tightly fit the image, regardless of dataLim. Autoscaling
state is not changed, so a subsequent call to Axes.autoscale_view
will redo the autoscaling in accord with dataLim.
Bases: _ImageBase
The Image class whose size is determined by the given bbox.
The bbox or a function to generate the bbox
Warning
If using matplotlib.artist.Artist.get_window_extent as the
callable ensure that the other artist is drawn first (lower zorder)
or you may need to renderer the figure twice to ensure that the
computed bbox is accurate.
Colormap, default: rcParams["image.cmap"] (default: 'viridis')The Colormap instance or registered colormap name used to map scalar data to colors. This parameter is ignored if X is RGB(A).
NormalizeMaps luminance to 0-1. This parameter is ignored if X is RGB(A).
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'.
rcParams["image.origin"] (default: 'upper')Place the [0, 0] index of the array in the upper left or lower left corner of the Axes. The convention 'upper' is typically used for matrices and images.
A parameter for the antigrain image resize filter (see the antigrain documentation). If filternorm is set, 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.
The filter radius for filters that have a radius parameter, i.e. when interpolation is one of: 'sinc', 'lanczos' or 'blackman'.
When True, use a full resampling method. When False, only resample when the output image is larger than the input image.
Artist propertiescolorizer.ColorizerGet the artist's bounding box in display space, ignoring clipping.
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 bounding box at 0, 0.
Warning
The extent can change due to any changes in the transform stack, such as changing the Axes limits, the figure size, the canvas used (as is done when saving a figure), or the DPI.
Relying on a once-retrieved window extent can lead to unexpected behavior in various cases such as interactive figures being resized or moved to a screen with different dpi, or figures that look fine on screen render incorrectly when saved to file.
To get accurate results you may need to manually call
savefig or draw_without_rendering to have
Matplotlib compute the rendered size.
RendererBase, optionalRenderer used to draw the figure (i.e. fig.canvas.get_renderer()).
See also
Artist.get_tightbboxGet the artist bounding box, taking clipping into account.
Normalize, rescale, and colormap this image's data for rendering using renderer, with the given magnification.
If unsampled is True, the image will not be scaled, but an appropriate affine transformation will be returned instead.
numpy.uint8 arrayThe RGBA image, resampled unless unsampled is True.
The upper left corner where the image should be drawn, in pixel space.
Affine2DThe affine transformation from image to pixel space.
Set multiple properties at once.
a.set(a=A, b=B, c=C)
is equivalent to
a.set_a(A)
a.set_b(B)
a.set_c(C)
In addition to the full property names, aliases are also supported, e.g.
set(lw=2) is equivalent to set(linewidth=2), but it is an error
to pass both simultaneously.
The order of the individual setter calls matches the order of parameters
in set(). However, most properties do not depend on each other so
that order is rarely relevant.
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
alphafloat or 2D array-like or None
bool
arrayarray-like
(vmin: float, vmax: float)
BboxBaseor Nonebool
Patch or (Path, Transform) or None
Colormapor str or None
dataarray-like or
PIL.Image.Image
filternormbool
filterradpositive 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
Normalizeor str or Nonelist of
AbstractPathEffectNone or bool or float or callable
bool
resamplebool, default:
rcParams["image.resample"](default:True)(scale: float, length: float, randomness: float)
bool or None
str
bool
float
Bases: _ImageBase
An image attached to a figure.
cmap is a colors.Colormap instance norm is a colors.Normalize instance to map luminance to 0-1
kwargs are an optional list of Artist keyword args
Normalize, rescale, and colormap this image's data for rendering using renderer, with the given magnification.
If unsampled is True, the image will not be scaled, but an appropriate affine transformation will be returned instead.
numpy.uint8 arrayThe RGBA image, resampled unless unsampled is True.
The upper left corner where the image should be drawn, in pixel space.
Affine2DThe affine transformation from image to pixel space.
Set multiple properties at once.
a.set(a=A, b=B, c=C)
is equivalent to
a.set_a(A)
a.set_b(B)
a.set_c(C)
In addition to the full property names, aliases are also supported, e.g.
set(lw=2) is equivalent to set(linewidth=2), but it is an error
to pass both simultaneously.
The order of the individual setter calls matches the order of parameters
in set(). However, most properties do not depend on each other so
that order is rarely relevant.
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
alphafloat or 2D array-like or None
bool
arrayarray-like
(vmin: float, vmax: float)
BboxBaseor Nonebool
Patch or (Path, Transform) or None
Colormapor str or Noneunknown
filternormbool
filterradpositive 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
Normalizeor str or Nonelist of
AbstractPathEffectNone or bool or float or callable
bool
resamplebool, default:
rcParams["image.resample"](default:True)(scale: float, length: float, randomness: float)
bool or None
str
bool
float
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 also Image nonuniform.
Return the image value at the event position or None if the event is outside the image.
Normalize, rescale, and colormap this image's data for rendering using renderer, with the given magnification.
If unsampled is True, the image will not be scaled, but an appropriate affine transformation will be returned instead.
numpy.uint8 arrayThe RGBA image, resampled unless unsampled is True.
The upper left corner where the image should be drawn, in pixel space.
Affine2DThe affine transformation from image to pixel space.
Set multiple properties at once.
a.set(a=A, b=B, c=C)
is equivalent to
a.set_a(A)
a.set_b(B)
a.set_c(C)
In addition to the full property names, aliases are also supported, e.g.
set(lw=2) is equivalent to set(linewidth=2), but it is an error
to pass both simultaneously.
The order of the individual setter calls matches the order of parameters
in set(). However, most properties do not depend on each other so
that order is rarely relevant.
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
alphafloat or 2D array-like or None
bool
arrayunknown
(vmin: float, vmax: float)
BboxBaseor Nonebool
Patch or (Path, Transform) or None
unknown
unknown
4-tuple of float
filternormunknown
filterradunknown
str
bool
{'nearest', 'bilinear'} or None
interpolation_stage{'data', 'rgba', 'auto'}, default:
rcParams["image.interpolation_stage"](default:'auto')object
bool
unknown
list of
AbstractPathEffectNone or bool or float or callable
bool
resamplebool, default:
rcParams["image.resample"](default:True)(scale: float, length: float, randomness: float)
bool or None
str
bool
float
Retained for backwards compatibility - use set_data instead.
Set the colormap for luminance data.
Colormap or str or NoneSet the grid for the pixel centers, and the pixel values.
Monotonic arrays of shapes (N,) and (M,), respectively, specifying pixel centers.
(M, N) ndarray or masked array of values to be
colormapped, or (M, N, 3) RGB array, or (M, N, 4) RGBA array.
Set whether the resize filter normalizes the weights.
See help for imshow.
Set the resize filter radius (only applicable to some interpolation schemes).
See help for imshow.
If None, use rcParams["image.interpolation"] (default: 'auto').
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.
AxesThe Axes the image will belong to.
Monotonic arrays of length N+1 and M+1, respectively, specifying
rectangle boundaries. If not given, will default to
range(N + 1) and range(M + 1), respectively.
The data to be color-coded. The interpretation depends on the shape:
(M, N) ndarray or masked array: values to be colormapped
(M, N, 3): RGB array
(M, N, 4): RGBA array
Colormap, default: rcParams["image.cmap"] (default: 'viridis')The Colormap instance or registered colormap name used to map scalar data to colors.
NormalizeMaps luminance to 0-1.
Artist propertiesReturn the image value at the event position or None if the event is outside the image.
Normalize, rescale, and colormap this image's data for rendering using renderer, with the given magnification.
If unsampled is True, the image will not be scaled, but an appropriate affine transformation will be returned instead.
numpy.uint8 arrayThe RGBA image, resampled unless unsampled is True.
The upper left corner where the image should be drawn, in pixel space.
Affine2DThe affine transformation from image to pixel space.
Set multiple properties at once.
a.set(a=A, b=B, c=C)
is equivalent to
a.set_a(A)
a.set_b(B)
a.set_c(C)
In addition to the full property names, aliases are also supported, e.g.
set(lw=2) is equivalent to set(linewidth=2), but it is an error
to pass both simultaneously.
The order of the individual setter calls matches the order of parameters
in set(). However, most properties do not depend on each other so
that order is rarely relevant.
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
alphafloat or 2D array-like or None
bool
arrayunknown
(vmin: float, vmax: float)
BboxBaseor Nonebool
Patch or (Path, Transform) or None
Colormapor str or Noneunknown
4-tuple of float
filternormbool
filterradpositive 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
Normalizeor str or Nonelist of
AbstractPathEffectNone or bool or float or callable
bool
resamplebool, default:
rcParams["image.resample"](default:True)(scale: float, length: float, randomness: float)
bool or None
str
bool
float
Retained for backwards compatibility - use set_data instead.
Set the grid for the rectangle boundaries, and the data values.
Monotonic arrays of length N+1 and M+1, respectively, specifying
rectangle boundaries. If not given, will default to
range(N + 1) and range(M + 1), respectively.
The data to be color-coded. The interpretation depends on the shape:
(M, N) ndarray or masked array: values to be colormapped
(M, N, 3): RGB array
(M, N, 4): RGBA array
Composite a number of RGBA images into one. The images are composited in the order in which they appear in the images list.
Each must have a make_image method. For each image,
can_composite should return True, though this is not
enforced by this function. Each image must have a purely
affine transformation with no shear.
RendererBaseThe additional magnification to apply for the renderer in use.
numpy.uint8 arrayThe composited RGBA image.
The (left, bottom) offset where the composited image should be placed in the output figure.
Read an image from a file into an array.
Note
This function exists for historical reasons. It is recommended to
use PIL.Image.open instead for loading images.
The image file to read: a filename, a URL or a file-like object opened in read-binary mode.
Passing a URL is deprecated. Please open the URL
for reading and pass the result to Pillow, e.g. with
np.array(PIL.Image.open(urllib.request.urlopen(url))).
The image file format assumed for reading the data. The image is
loaded as a PNG file if format is set to "png", if fname is a path
or opened file with a ".png" extension, or if it is a URL. In all
other cases, format is ignored and the format is auto-detected by
PIL.Image.open.
numpy.arrayThe 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 are returned as int arrays, with a bit depth determined by the file's contents.
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 pillow, tifffile, or imageio) directly.
A path or a file-like object to store the image in.
If format is not set, then the output format is inferred from the
extension of fname, if any, and from rcParams["savefig.format"] (default: 'png') otherwise.
If format is set, it determines the output format.
The image data. Accepts NumPy arrays or sequences (e.g., lists or tuples). The shape can be one of MxN (luminance), MxNx3 (RGB) or MxNx4 (RGBA).
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.
Colormap, default: rcParams["image.cmap"] (default: 'viridis')A Colormap instance or registered colormap name. The colormap maps scalar data to colors. It is ignored for RGB(A) data.
The file format, e.g. 'png', 'pdf', 'svg', ... The behavior when this is unset is documented under fname.
rcParams["image.origin"] (default: 'upper')Indicates whether the (0, 0) index of the array is in the upper
left or lower left corner of the Axes.
The DPI to store in the metadata of the file. This does not affect the resolution of the output image. Depending on file format, this may be rounded to the nearest integer.
Metadata in the image file. The supported keys depend on the output format, see the documentation of the respective backends for more information. Currently only supported for "png", "pdf", "ps", "eps", and "svg".
Keyword arguments passed to PIL.Image.Image.save. If the 'pnginfo'
key is present, it completely overrides metadata, including the
default 'Software' key.
Load a PIL image and return it as a numpy int 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.
[Deprecated] Make a thumbnail of image in infile with output filename thumbfile.
The image file. Matplotlib relies on Pillow for image reading, and thus supports a wide range of file formats, including PNG, JPG, TIFF and others.
The thumbnail filename.
The scale factor for the thumbnail.
The interpolation scheme used in the resampling. See the
interpolation parameter of imshow for possible values.
If True, the default backend (presumably a user interface
backend) will be used which will cause a figure to be raised if
show is called. If it is False, the figure is
created using FigureCanvasBase and the drawing backend is selected
as Figure.savefig would normally do.
FigureThe figure instance containing the thumbnail.
Notes
Deprecated since version 3.11: Use Pillow's PIL.Image.Image.thumbnail instead.
| Web Proxy Viewer | New URL | Original Page |