Create a pseudocolor plot with a non-regular rectangular grid.
Call signature:
pcolormesh([X, Y,] C, **kwargs)
X and Y can be used to specify the corners of the quadrilaterals.
Hint
pcolormesh
is similar to pcolor
. It is much faster and preferred in most cases. For a detailed discussion on the differences see Differences between pcolor() and pcolormesh().
The color-mapped values.
The coordinates of the corners of quadrilaterals of a pcolormesh:
(X[i+1, j], Y[i+1, j]) (X[i+1, j+1], Y[i+1, j+1]) +-----+ | | +-----+ (X[i, j], Y[i, j]) (X[i, j+1], Y[i, j+1])
Note that the column index corresponds to the x-coordinate, and the row index corresponds to y. For details, see the Notes section below.
If shading='flat'
the dimensions of X and Y should be one greater than those of C, and the quadrilateral is colored due to the value at C[i, j]
. If X, Y and C have equal dimensions, a warning will be raised and the last row and column of C will be ignored.
If shading='nearest'
or 'gouraud'
, the dimensions of X and Y should be the same as those of C (if not, a ValueError will be raised). For 'nearest'
the color C[i, j]
is centered on (X[i, j], Y[i, j])
. For 'gouraud'
, a smooth interpolation is caried out between the quadrilateral corners.
If X and/or Y are 1-D arrays or column vectors they will be expanded as needed into the appropriate 2D arrays, making a rectangular grid.
Colormap
, default: rcParams["image.cmap"]
(default: 'viridis'
)
A Colormap instance or registered colormap name. The colormap maps the C values to colors.
Normalize
, optional
The Normalize instance scales the data values to the canonical colormap range [0, 1] for mapping to colors. By default, the data range is mapped to the colorbar range using linear scaling.
The colorbar range. If None, suitable min/max values are automatically chosen by the Normalize
instance (defaults to the respective min/max values of C in case of the default linear scaling). It is an error to use vmin/vmax when norm is given.
The color of the edges. Defaults to 'none'. Possible values:
rcParams["patch.edgecolor"]
(default: 'black'
) will be used. Note that currently rcParams["patch.force_edgecolor"]
(default: False
) has to be True for this to work.The singular form edgecolor works as an alias.
The alpha blending value, between 0 (transparent) and 1 (opaque).
The fill style for the quadrilateral; defaults to 'flat' or rcParams["pcolor.shading"]
(default: 'auto'
). Possible values:
C[i, j]
. The dimensions of X and Y should be one greater than those of C; if they are the same as C, then a deprecation warning is raised, and the last row and column of C are dropped.C[i', j']
. The color values of the area in between is interpolated from the corner values. The dimensions of X and Y must be the same as C. When Gouraud shading is used, edgecolors is ignored.See pcolormesh grids and shading for more description.
Whether to snap the mesh to pixel boundaries.
Rasterize the pcolormesh when drawing vector graphics. This can speed up rendering and produce smaller files for large data sets. See also Rasterization for vector graphics.
If given, all parameters also accept a string s
, which is interpreted as data[s]
(unless this raises an exception).
Additionally, the following arguments are allowed. They are passed along to the QuadMesh
constructor:
Property | Description |
---|---|
a filter function, which takes a (m, n, 3) float array and a dpi value, and returns a (m, n, 3) array | |
array-like or scalar or None | |
bool | |
| bool or list of bools |
(M, N) array-like or M*N array-like | |
| |
(vmin: float, vmax: float) | |
bool | |
Patch or (Path, Transform) or None | |
| |
color or list of rgba tuples | |
| color or list of colors or 'face' |
| color or list of colors |
str | |
{'/', '\', '|', '-', '+', 'x', 'o', 'O', '.', '*'} | |
bool | |
| |
object | |
| str or tuple or list thereof |
| float or list of floats |
| |
(N, 2) or (2,) array-like | |
None or bool or float or callable | |
float | |
bool | |
(scale: float, length: float, randomness: float) | |
bool or None | |
str | |
list of str or None | |
bool | |
float |
See also
pcolor
An alternative implementation with slightly different features. For a detailed discussion on the differences see Differences between pcolor() and pcolormesh().
imshow
If X and Y are each equidistant, imshow
can be a faster alternative.
Masked arrays
C may be a masked array. If C[i, j]
is masked, the corresponding quadrilateral will be transparent. Masking of X and Y is not supported. Use pcolor
if you need this functionality.
Grid orientation
The grid orientation follows the standard matrix convention: An array C with shape (nrows, ncolumns) is plotted with the column number as X and the row number as Y.
Differences between pcolor() and pcolormesh()
Both methods are used to create a pseudocolor plot of a 2D array using quadrilaterals.
The main difference lies in the created object and internal data handling: While pcolor
returns a PolyCollection
, pcolormesh
returns a QuadMesh
. The latter is more specialized for the given purpose and thus is faster. It should almost always be preferred.
There is also a slight difference in the handling of masked arrays. Both pcolor
and pcolormesh
support masked arrays for C. However, only pcolor
supports masked arrays for X and Y. The reason lies in the internal handling of the masked values. pcolor
leaves out the respective polygons from the PolyCollection. pcolormesh
sets the facecolor of the masked elements to transparent. You can see the difference when using edgecolors. While all edges are drawn irrespective of masking in a QuadMesh, the edge between two adjacent masked quadrilaterals in pcolor
is not drawn as the corresponding polygons do not exist in the PolyCollection.
Another difference is the support of Gouraud shading in pcolormesh
, which is not available with pcolor
.
matplotlib.axes.Axes.pcolormesh
© 2012–2021 Matplotlib Development Team. All rights reserved.
Licensed under the Matplotlib License Agreement.
https://matplotlib.org/3.5.1/api/_as_gen/matplotlib.axes.Axes.pcolormesh.html