matplotlib.pyplot.tricontourf#
- matplotlib.pyplot.tricontourf(*args,**kwargs)[source]#
Draw contour regions on an unstructured triangular grid.
Call signatures:
tricontourf(triangulation,z,[levels],...)tricontourf(x,y,z,[levels],*,[triangles=triangles],[mask=mask],...)
The triangular grid can be specified either by passing a
Triangulation
object as the first parameter, or by passing the pointsx,y andoptionally thetriangles and amask. SeeTriangulation
for anexplanation of these parameters. If neither oftriangulation ortriangles are given, the triangulation is calculated on the fly.It is possible to passtriangles positionally, i.e.
tricontourf(x,y,triangles,z,...)
. However, this is discouraged. For moreclarity, passtriangles via keyword argument.- Parameters:
- triangulation
Triangulation
, optional An already created triangular grid.
- x, y, triangles, mask
Parameters defining the triangular grid. See
Triangulation
.This is mutually exclusive with specifyingtriangulation.- zarray-like
The height values over which the contour is drawn. Color-mapping iscontrolled bycmap,norm,vmin, andvmax.
Note
All values inz must be finite. Hence, nan and inf values musteither be removed or
set_mask
be used.- levelsint or array-like, optional
Determines the number and positions of the contour lines / regions.
If an intn, use
MaxNLocator
, which tries toautomatically choose no more thann+1 "nice" contour levels betweenbetween minimum and maximum numeric values ofZ.If array-like, draw contour lines at the specified levels. The values mustbe in increasing order.
- triangulation
- Returns:
- Other Parameters:
- colorscolor or list ofcolor, optional
The colors of the levels, i.e., the contour regions.
The sequence is cycled for the levels in ascending order. If the sequenceis shorter than the number of levels, it is repeated.
As a shortcut, single color strings may be used in place of one-elementlists, i.e.
'red'
instead of['red']
to color all levels with thesame color. This shortcut does only work for color strings, not for otherways of specifying colors.By default (valueNone), the colormap specified bycmap will be used.
- alphafloat, default: 1
The alpha blending value, between 0 (transparent) and 1 (opaque).
- cmapstr or
Colormap
, default:rcParams["image.cmap"]
(default:'viridis'
) The Colormap instance or registered colormap name used to map scalar datato colors.
This parameter is ignored ifcolors is set.
- 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.
This parameter is ignored ifcolors is set.
- 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).Ifvmin orvmax are not given, the default color scaling is based onlevels.
This parameter is ignored ifcolors is set.
- origin{None, 'upper', 'lower', 'image'}, default: None
Determines the orientation and exact position ofz by specifying theposition of
z[0,0]
. This is only relevant, ifX,Y are not given.None:
z[0,0]
is at X=0, Y=0 in the lower left corner.'lower':
z[0,0]
is at X=0.5, Y=0.5 in the lower left corner.'upper':
z[0,0]
is at X=N+0.5, Y=0.5 in the upper left corner.'image': Use the value from
rcParams["image.origin"]
(default:'upper'
).
- extent(x0, x1, y0, y1), optional
Iforigin is notNone, thenextent is interpreted as in
imshow
: itgives the outer pixel boundaries. In this case, the position of z[0, 0] isthe center of the pixel, not a corner. Iforigin isNone, then(x0,y0) is the position of z[0, 0], and (x1,y1) is the positionof z[-1, -1].This argument is ignored ifX andY are specified in the call tocontour.
- locatorticker.Locator subclass, optional
The locator is used to determine the contour levels if they are not givenexplicitly vialevels.Defaults to
MaxNLocator
.- extend{'neither', 'both', 'min', 'max'}, default: 'neither'
Determines the
tricontourf
-coloring of values that are outside thelevels range.If 'neither', values outside thelevels range are not colored. If 'min','max' or 'both', color the values below, above or below and above thelevels range.
Values below
min(levels)
and abovemax(levels)
are mapped to theunder/over values of theColormap
. Note that most colormaps do not havededicated colors for these by default, so that the over and under valuesare the edge values of the colormap. You may want to set these valuesexplicitly usingColormap.set_under
andColormap.set_over
.Note
An existing
TriContourSet
does not get notified if properties of itscolormap are changed. Therefore, an explicit call toContourSet.changed()
is needed after modifying the colormap. Theexplicit call can be left out, if a colorbar is assigned to theTriContourSet
because it internally callsContourSet.changed()
.- xunits, yunitsregistered units, optional
Override axis units by specifying an instance of a
matplotlib.units.ConversionInterface
.- antialiasedbool, optional
Enable antialiasing, overriding the defaults. Forfilled contours, the default isTrue. For line contours,it is taken from
rcParams["lines.antialiased"]
(default:True
).- hatcheslist[str], optional
A list of crosshatch patterns to use on the filled areas.If None, no hatching will be added to the contour.
Notes
Note
This is thepyplot wrapper for
axes.Axes.tricontourf
.tricontourf
fills intervals that are closed at the top; that is, forboundariesz1 andz2, the filled region is:z1<Z<=z2
except for the lowest interval, which is closed on both sides (i.e. itincludes the lowest value).