matplotlib.pyplot.pcolor#
- matplotlib.pyplot.pcolor(*args,shading=None,alpha=None,norm=None,cmap=None,vmin=None,vmax=None,colorizer=None,data=None,**kwargs)[source]#
Create a pseudocolor plot with a non-regular rectangular grid.
Call signature:
pcolor([X,Y,]C,/,**kwargs)
X andY can be used to specify the corners of the quadrilaterals.
The argumentsX,Y,C are positional-only.
Hint
pcolor()
can be very slow for large arrays. In mostcases you should use the similar but much fasterpcolormesh
instead. SeeDifferences between pcolor() and pcolormesh() for a discussion of thedifferences.- Parameters:
- C2D array-like
The color-mapped values. Color-mapping is controlled bycmap,norm,vmin, andvmax.
- X, Yarray-like, optional
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, andthe row index corresponds to y. For details, see theNotes section below.
If
shading='flat'
the dimensions ofX andY should be onegreater than those ofC, and the quadrilateral is colored dueto the value atC[i,j]
. IfX,Y andC have equaldimensions, a warning will be raised and the last row and columnofC will be ignored.If
shading='nearest'
, the dimensions ofX andY should bethe same as those ofC (if not, a ValueError will be raised). ThecolorC[i,j]
will be centered on(X[i,j],Y[i,j])
.IfX and/orY are 1-D arrays or column vectors they will beexpanded as needed into the appropriate 2D arrays, making arectangular grid.
- shading{'flat', 'nearest', 'auto'}, default:
rcParams["pcolor.shading"]
(default:'auto'
) The fill style for the quadrilateral. Possible values:
'flat': A solid color is used for each quad. The color of thequad (i, j), (i+1, j), (i, j+1), (i+1, j+1) is given by
C[i,j]
. The dimensions ofX andY should beone greater than those ofC; if they are the same asC,then a deprecation warning is raised, and the last rowand column ofC are dropped.'nearest': Each grid point will have a color centered on it,extending halfway between the adjacent grid centers. Thedimensions ofX andY must be the same asC.
'auto': Choose 'flat' if dimensions ofX andY are onelarger thanC. Choose 'nearest' if dimensions are the same.
Seepcolormesh grids and shadingfor more description.
- cmapstr or
Colormap
, default:rcParams["image.cmap"]
(default:'viridis'
) The Colormap instance or registered colormap name used to map scalar datato colors.
- normstr or
Normalize
, optional The normalization method used to scale scalar data to the [0, 1] rangebefore mapping to colors usingcmap. By default, a linear scaling isused, mapping the lowest value to 0 and the highest to 1.
If given, this can be one of the following:
An instance of
Normalize
or one of its subclasses(seeColormap normalization).A scale name, i.e. one of "linear", "log", "symlog", "logit", etc. For alist of available scales, call
matplotlib.scale.get_scale_names()
.In that case, a suitableNormalize
subclass is dynamically generatedand instantiated.
- vmin, vmaxfloat, optional
When using scalar data and no explicitnorm,vmin andvmax definethe data range that the colormap covers. By default, the colormap coversthe complete value range of the supplied data. It is an error to usevmin/vmax when anorm instance is given (but using a
str
normname together withvmin/vmax is acceptable).- colorizer
Colorizer
or None, default: None The Colorizer object used to map color to data. If None, a Colorizerobject is created from anorm andcmap.
- edgecolors{'none', None, 'face', color, color sequence}, optional
The color of the edges. Defaults to 'none'. Possible values:
'none' or '': No edge.
None:
rcParams["patch.edgecolor"]
(default:'black'
) will be used. Note that currentlyrcParams["patch.force_edgecolor"]
(default:False
) has to be True for this to work.'face': Use the adjacent face color.
A color or sequence of colors will set the edge color.
The singular formedgecolor works as an alias.
- alphafloat, default: None
The alpha blending value of the face color, between 0 (transparent)and 1 (opaque). Note: The edgecolor is currently not affected bythis.
- snapbool, default: False
Whether to snap the mesh to pixel boundaries.
- Returns:
- Other Parameters:
- antialiasedsbool, default: False
The defaultantialiaseds is False if the defaultedgecolors="none" is used. This eliminates artificial linesat patch boundaries, and works regardless of the value of alpha.Ifedgecolors is not "none", then the defaultantialiasedsis taken from
rcParams["patch.antialiased"]
(default:True
).Stroking the edges may be preferred ifalpha is 1, but willcause artifacts otherwise.- dataindexable object, optional
If given, all parameters also accept a string
s
, which isinterpreted asdata[s]
ifs
is a key indata
.- **kwargs
Additionally, the following arguments are allowed. They are passedalong to the
PolyQuadMesh
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 and two offsets from the bottom left corner of the image
array-like or float or None
bool
bool or list of bools
array-like or None
CapStyle
or {'butt', 'projecting', 'round'}(vmin: float, vmax: float)
BboxBase
or Nonebool
Patch or (Path, Transform) or None
Colormap
or str or Nonecolor or list of RGBA tuples
edgecolor
orec
oredgecolors
facecolor
orfacecolors
orfc
str
{'/', '\', '|', '-', '+', 'x', 'o', 'O', '.', '*'}
unknown
bool
JoinStyle
or {'miter', 'round', 'bevel'}object
linestyle
ordashes
orlinestyles
orls
str or tuple or list thereof
linewidth
orlinewidths
orlw
float or list of floats
bool
Normalize
or str or None(N, 2) or (2,) array-like
list of
AbstractPathEffect
list of array-like
None or bool or float or callable
float
bool
numpy.ndarray
or None(scale: float, length: float, randomness: float)
bool or None
str
list of str or None
list of array-like
unknown
bool
float
See also
pcolormesh
for an explanation of the differences between pcolor and pcolormesh.
imshow
IfX andY are each equidistant,
imshow
can be a faster alternative.
Notes
Note
This is thepyplot wrapper for
axes.Axes.pcolor
.Masked arrays
X,Y andC may be masked arrays. If either
C[i,j]
, or oneof the vertices surroundingC[i,j]
(X orY at[i,j],[i+1,j],[i,j+1],[i+1,j+1]
) is masked, nothing isplotted.Grid orientation
The grid orientation follows the standard matrix convention: An arrayC with shape (nrows, ncolumns) is plotted with the column number asX and the row number asY.
Examples usingmatplotlib.pyplot.pcolor
#

Controlling view limits using margins and sticky_edges