xarray.DataArray.plot.imshow¶
-
DataArray.plot.
imshow
(x, y, **kwargs)[source]¶ Image plot of 2D DataArray.
Wraps
matplotlib.pyplot.imshow()
.While other plot methods require the DataArray to be strictly two-dimensional,
imshow
also accepts a 3D array where some dimension can be interpreted as RGB or RGBA color channels and allows this dimension to be specified via the kwargrgb=
.Unlike
matplotlib.pyplot.imshow()
, which ignoresvmin
/vmax
for RGB(A) data, xarray will usevmin
andvmax
for RGB(A) data by applying a single scaling factor and offset to all bands. Passingrobust=True
infersvmin
andvmax
in the usual way.Note
This function needs uniformly spaced coordinates to properly label the axes. Call
DataArray.plot()
to check.The pixels are centered on the coordinates. For example, if the coordinate value is 3.2, then the pixels for those coordinates will be centered on 3.2.
- Parameters
darray (
DataArray
) – Must be two-dimensional, unless creating faceted plots.x (
str
, optional) – Coordinate for x axis. IfNone
, usedarray.dims[1]
.y (
str
, optional) – Coordinate for y axis. IfNone
, usedarray.dims[0]
.figsize (
tuple
, optional) – A tuple (width, height) of the figure in inches. Mutually exclusive withsize
andax
.aspect (scalar, optional) – Aspect ratio of plot, so that
aspect * size
gives the width in inches. Only used if asize
is provided.size (scalar, optional) – If provided, create a new figure for the plot with the given size: height (in inches) of each plot. See also:
aspect
.ax (
matplotlib axes object
, optional) – Axes on which to plot. By default, use the current axes. Mutually exclusive withsize
andfigsize
.row (
string
, optional) – If passed, make row faceted plots on this dimension name.col (
string
, optional) – If passed, make column faceted plots on this dimension name.col_wrap (
int
, optional) – Use together withcol
to wrap faceted plots.xscale, yscale (
{'linear', 'symlog', 'log', 'logit'}
, optional) – Specifies scaling for the x- and y-axis, respectively.xticks, yticks (array-like, optional) – Specify tick locations for x- and y-axis.
xlim, ylim (array-like, optional) – Specify x- and y-axis limits.
xincrease (
None
,True
, orFalse
, optional) – Should the values on the x axis be increasing from left to right? IfNone
, use the default for the Matplotlib function.yincrease (
None
,True
, orFalse
, optional) – Should the values on the y axis be increasing from top to bottom? IfNone
, use the default for the Matplotlib function.add_colorbar (
bool
, optional) – Add colorbar to axes.add_labels (
bool
, optional) – Use xarray metadata to label axes.norm (
matplotlib.colors.Normalize
, optional) – Ifnorm
hasvmin
orvmax
specified, the corresponding kwarg must beNone
.vmin, vmax (
float
, optional) – Values to anchor the colormap, otherwise they are inferred from the data and other keyword arguments. When a diverging dataset is inferred, setting one of these values will fix the other by symmetry aroundcenter
. Setting both values prevents use of a diverging colormap. If discrete levels are provided as an explicit list, both of these values are ignored.cmap (matplotlib colormap name or
colormap
, optional) – The mapping from data values to color space. If not provided, this will be either be'viridis'
(if the function infers a sequential dataset) or'RdBu_r'
(if the function infers a diverging dataset). See Choosing Colormaps in Matplotlib for more information.If seaborn is installed,
cmap
may also be a seaborn color palette. Note: ifcmap
is a seaborn color palette and the plot type is not'contour'
or'contourf'
,levels
must also be specified.colors (
str
or array-like ofcolor-like
, optional) – A single color or a sequence of colors. If the plot type is not'contour'
or'contourf'
, thelevels
argument is required.center (
float
, optional) – The value at which to center the colormap. Passing this value implies use of a diverging colormap. Setting it toFalse
prevents use of a diverging colormap.robust (
bool
, optional) – IfTrue
andvmin
orvmax
are absent, the colormap range is computed with 2nd and 98th percentiles instead of the extreme values.extend (
{'neither', 'both', 'min', 'max'}
, optional) – How to draw arrows extending the colorbar beyond its limits. If not provided,extend
is inferred fromvmin
,vmax
and the data limits.levels (
int
or array-like, optional) – Split the colormap (cmap
) into discrete color intervals. If an integer is provided, “nice” levels are chosen based on the data range: this can imply that the final number of levels is not exactly the expected one. Settingvmin
and/orvmax
withlevels=N
is equivalent to settinglevels=np.linspace(vmin, vmax, N)
.infer_intervals (
bool
, optional) – Only applies to pcolormesh. IfTrue
, the coordinate intervals are passed to pcolormesh. IfFalse
, the original coordinates are used (this can be useful for certain map projections). The default is to always infer intervals, unless the mesh is irregular and plotted on a map projection.subplot_kws (
dict
, optional) – Dictionary of keyword arguments for Matplotlib subplots. Only used for 2D and faceted plots. (seematplotlib.figure.Figure.add_subplot()
).cbar_ax (
matplotlib axes object
, optional) – Axes in which to draw the colorbar.cbar_kwargs (
dict
, optional) – Dictionary of keyword arguments to pass to the colorbar (seematplotlib.figure.Figure.colorbar()
).**kwargs (optional) – Additional keyword arguments to wrapped Matplotlib function.
- Returns
artist
– The same type of primitive artist that the wrapped Matplotlib function returns.