matplotlib.contour#
Classes to support contour plotting and labelling for the Axes class.
- classmatplotlib.contour.ContourLabeler[source]#
Bases:
objectMixin to provide labelling capability to
ContourSet.- add_label(x,y,rotation,lev,cvalue)[source]#
Add a contour label, respecting whetheruse_clabeltext was set.
- add_label_near(x,y,inline=True,inline_spacing=5,transform=None)[source]#
Add a label near the point
(x,y).- Parameters:
- x, yfloat
The approximate location of the label.
- inlinebool, default: True
IfTrue remove the segment of the contour beneath the label.
- inline_spacingint, default: 5
Space in pixels to leave on each side of label when placinginline. This spacing will be exact for labels at locations wherethe contour is straight, less so for labels on curved contours.
- transform
TransformorFalse, default:self.axes.transData A transform applied to
(x,y)before labeling. The defaultcauses(x,y)to be interpreted as data coordinates.Falseis a synonym forIdentityTransform; i.e.(x,y)should beinterpreted as display coordinates.
- clabel(levels=None,*,fontsize=None,inline=True,inline_spacing=5,fmt=None,colors=None,use_clabeltext=False,manual=False,rightside_up=True,zorder=None)[source]#
Label a contour plot.
Adds labels to line contours in this
ContourSet(which inherits fromthis mixin class).- Parameters:
- levelsarray-like, optional
A list of level values, that should be labeled. The list must bea subset of
cs.levels. If not given, all levels are labeled.- fontsizestr or float, default:
rcParams["font.size"](default:10.0) Size in points or relative size e.g., 'smaller', 'x-large'.See
Text.set_sizefor accepted string values.- colorscolor or colors or None, default: None
The label colors:
IfNone, the color of each label matches the color ofthe corresponding contour.
If one string color, e.g.,colors = 'r' orcolors ='red', all labels will be plotted in this color.
If a tuple of colors (string, float, RGB, etc), different labelswill be plotted in different colors in the order specified.
- inlinebool, default: True
If
Truethe underlying contour is removed where the label isplaced.- inline_spacingfloat, default: 5
Space in pixels to leave on each side of label when placing inline.
This spacing will be exact for labels at locations where thecontour is straight, less so for labels on curved contours.
- fmt
Formatteror str or callable or dict, optional How the levels are formatted:
If a
Formatter, it is used to format all levels at once, usingitsFormatter.format_ticksmethod.If a str, it is interpreted as a %-style format string.
If a callable, it is called with one level at a time and shouldreturn the corresponding label.
If a dict, it should directly map levels to labels.
The default is to use a standard
ScalarFormatter.- manualbool or iterable, default: False
If
True, contour labels will be placed manually usingmouse clicks. Click the first button near a contour toadd a label, click the second button (or potentially bothmouse buttons at once) to finish adding labels. The thirdbutton can be used to remove the last label added, butonly if labels are not inline. Alternatively, the keyboardcan be used to select label locations (enter to end labelplacement, delete or backspace act like the third mouse button,and any other key will select a label location).manual can also be an iterable object of (x, y) tuples.Contour labels will be created as if mouse is clicked at each(x, y) position.
- rightside_upbool, default: True
If
True, label rotations will always be plusor minus 90 degrees from level.- use_clabeltextbool, default: False
If
True, useText.set_transform_rotates_textto ensure thatlabel rotation is updated whenever the Axes aspect changes.- zorderfloat or None, default:
(2+contour.get_zorder()) zorder of the contour labels.
- Returns:
- labels
A list of
Textinstances for the labels.
- locate_label(linecontour,labelwidth)[source]#
Find good place to draw a label (relatively flat part of the contour).
- classmatplotlib.contour.ContourSet(ax,*args,levels=None,filled=False,linewidths=None,linestyles=None,hatches=(None,),alpha=None,origin=None,extent=None,cmap=None,colors=None,norm=None,vmin=None,vmax=None,colorizer=None,extend='neither',antialiased=None,nchunk=0,locator=None,transform=None,negative_linestyles=None,clip_path=None,**kwargs)[source]#
Bases:
ContourLabeler,CollectionStore a set of contour lines or filled regions.
User-callable method:
clabel- Parameters:
- ax
Axes - levels[level0, level1, ..., leveln]
A list of floating point numbers indicating the contour levels.
- allsegs[level0segs, level1segs, ...]
List of all the polygon segments for all thelevels.For contour lines
len(allsegs)==len(levels), and forfilled contour regionslen(allsegs)=len(levels)-1. The listsshould look likelevel0segs=[polygon0,polygon1,...]polygon0=[[x0,y0],[x1,y1],...]
- allkinds
Noneor [level0kinds, level1kinds, ...] Optional list of all the polygon vertex kinds (code types), asdescribed and used in Path. This is used to allow multiply-connected paths such as holes within filled polygons.If not
None,len(allkinds)==len(allsegs). The listsshould look likelevel0kinds=[polygon0kinds,...]polygon0kinds=[vertexcode0,vertexcode1,...]
Ifallkinds is not
None, usually all polygons for aparticular contour level are grouped together so thatlevel0segs=[polygon0]andlevel0kinds=[polygon0kinds].- **kwargs
Keyword arguments are as described in the docstring of
contour.
- ax
- Attributes:
- levelsarray
The values of the contour levels.
- layersarray
Same as levels for line contours; half-way betweenlevels for filled contours. See
ContourSet._process_colors.
Draw contour lines or filled regions, depending onwhether keyword argfilled is
False(default) orTrue.Call signature:
ContourSet(ax,levels,allsegs,[allkinds],**kwargs)
- Parameters:
- ax
Axes The
Axesobject to draw on.- levels[level0, level1, ..., leveln]
A list of floating point numbers indicating the contourlevels.
- allsegs[level0segs, level1segs, ...]
List of all the polygon segments for all thelevels.For contour lines
len(allsegs)==len(levels), and forfilled contour regionslen(allsegs)=len(levels)-1. The listsshould look likelevel0segs=[polygon0,polygon1,...]polygon0=[[x0,y0],[x1,y1],...]
- allkinds[level0kinds, level1kinds, ...], optional
Optional list of all the polygon vertex kinds (code types), asdescribed and used in Path. This is used to allow multiply-connected paths such as holes within filled polygons.If not
None,len(allkinds)==len(allsegs). The listsshould look likelevel0kinds=[polygon0kinds,...]polygon0kinds=[vertexcode0,vertexcode1,...]
Ifallkinds is not
None, usually all polygons for aparticular contour level are grouped together so thatlevel0segs=[polygon0]andlevel0kinds=[polygon0kinds].- **kwargs
Keyword arguments are as described in the docstring of
contour.
- ax
- propertyallkinds#
- propertyallsegs#
- propertyalpha#
- changed()[source]#
Call this whenever the mappable is changed to notify all thecallbackSM listeners to the 'changed' signal.
- draw(renderer)[source]#
Draw the Artist (and its children) using the given renderer.
This has no effect if the artist is not visible (
Artist.get_visiblereturns False).- Parameters:
- renderer
RendererBasesubclass.
- renderer
Notes
This method is overridden in the Artist subclasses.
- find_nearest_contour(x,y,indices=None,pixel=True)[source]#
Find the point in the contour plot that is closest to
(x,y).This method does not support filled contours.
- Parameters:
- x, yfloat
The reference point.
- indiceslist of int or None, default: None
Indices of contour levels to consider. If None (the default), alllevels are considered.
- pixelbool, default: True
IfTrue, measure distance in pixel (screen) space, which isuseful for manual contour labeling; else, measure distance in axesspace.
- Returns:
- pathint
The index of the path that is closest to
(x,y). Each path correspondsto one contour level.- subpathint
The index within that closest path of the subpath that is closest to
(x,y). Each subpath corresponds to one unbroken contour line.- indexint
The index of the vertices within that subpath that are closest to
(x,y).- xmin, yminfloat
The point in the contour plot that is closest to
(x,y).- d2float
The squared distance from
(xmin,ymin)to(x,y).
- legend_elements(variable_name='x',str_format=<class'str'>)[source]#
Return a list of artists and labels suitable for passing throughto
legendwhich represent this ContourSet.The labels have the form "0 < x <= 1" stating the data ranges whichthe artists represent.
- Parameters:
- variable_namestr
The string used inside the inequality used on the labels.
- str_formatfunction: float -> str
Function used to format the numbers in the labels.
- Returns:
- artistslist[
Artist] A list of the artists.
- labelslist[str]
A list of the labels.
- artistslist[
- propertylinestyles#
- set(*,agg_filter=<UNSET>,alpha=<UNSET>,animated=<UNSET>,antialiased=<UNSET>,array=<UNSET>,capstyle=<UNSET>,clim=<UNSET>,clip_box=<UNSET>,clip_on=<UNSET>,clip_path=<UNSET>,cmap=<UNSET>,color=<UNSET>,edgecolor=<UNSET>,facecolor=<UNSET>,gid=<UNSET>,hatch=<UNSET>,hatch_linewidth=<UNSET>,in_layout=<UNSET>,joinstyle=<UNSET>,label=<UNSET>,linestyle=<UNSET>,linewidth=<UNSET>,mouseover=<UNSET>,norm=<UNSET>,offset_transform=<UNSET>,offsets=<UNSET>,path_effects=<UNSET>,paths=<UNSET>,picker=<UNSET>,pickradius=<UNSET>,rasterized=<UNSET>,sketch_params=<UNSET>,snap=<UNSET>,transform=<UNSET>,url=<UNSET>,urls=<UNSET>,visible=<UNSET>,zorder=<UNSET>)[source]#
Set multiple properties at once.
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
array-like or float or None
bool
bool or list of bools
array-like or None
CapStyleor {'butt', 'projecting', 'round'}(vmin: float, vmax: float)
BboxBaseor Nonebool
Patch or (Path, Transform) or None
Colormapor str or Nonecolor or list of RGBA tuples
edgecolororecoredgecolorsfacecolororfacecolorsorfcstr
{'/', '\', '|', '-', '+', 'x', 'o', 'O', '.', '*'}
unknown
bool
JoinStyleor {'miter', 'round', 'bevel'}object
linestyleordashesorlinestylesorlsstr or tuple or list thereof
linewidthorlinewidthsorlwfloat or list of floats
bool
Normalizeor str or None(N, 2) or (2,) array-like
list of
AbstractPathEffectunknown
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
- classmatplotlib.contour.QuadContourSet(ax,*args,levels=None,filled=False,linewidths=None,linestyles=None,hatches=(None,),alpha=None,origin=None,extent=None,cmap=None,colors=None,norm=None,vmin=None,vmax=None,colorizer=None,extend='neither',antialiased=None,nchunk=0,locator=None,transform=None,negative_linestyles=None,clip_path=None,**kwargs)[source]#
Bases:
ContourSetCreate and store a set of contour lines or filled regions.
This class is typically not instantiated directly by the user but by
contourandcontourf.- Attributes:
- levelsarray
The values of the contour levels.
- layersarray
Same as levels for line contours; half-way betweenlevels for filled contours. See
ContourSet._process_colors.
Draw contour lines or filled regions, depending onwhether keyword argfilled is
False(default) orTrue.Call signature:
ContourSet(ax,levels,allsegs,[allkinds],**kwargs)
- Parameters:
- ax
Axes The
Axesobject to draw on.- levels[level0, level1, ..., leveln]
A list of floating point numbers indicating the contourlevels.
- allsegs[level0segs, level1segs, ...]
List of all the polygon segments for all thelevels.For contour lines
len(allsegs)==len(levels), and forfilled contour regionslen(allsegs)=len(levels)-1. The listsshould look likelevel0segs=[polygon0,polygon1,...]polygon0=[[x0,y0],[x1,y1],...]
- allkinds[level0kinds, level1kinds, ...], optional
Optional list of all the polygon vertex kinds (code types), asdescribed and used in Path. This is used to allow multiply-connected paths such as holes within filled polygons.If not
None,len(allkinds)==len(allsegs). The listsshould look likelevel0kinds=[polygon0kinds,...]polygon0kinds=[vertexcode0,vertexcode1,...]
Ifallkinds is not
None, usually all polygons for aparticular contour level are grouped together so thatlevel0segs=[polygon0]andlevel0kinds=[polygon0kinds].- **kwargs
Keyword arguments are as described in the docstring of
contour.
- ax
- set(*,agg_filter=<UNSET>,alpha=<UNSET>,animated=<UNSET>,antialiased=<UNSET>,array=<UNSET>,capstyle=<UNSET>,clim=<UNSET>,clip_box=<UNSET>,clip_on=<UNSET>,clip_path=<UNSET>,cmap=<UNSET>,color=<UNSET>,edgecolor=<UNSET>,facecolor=<UNSET>,gid=<UNSET>,hatch=<UNSET>,hatch_linewidth=<UNSET>,in_layout=<UNSET>,joinstyle=<UNSET>,label=<UNSET>,linestyle=<UNSET>,linewidth=<UNSET>,mouseover=<UNSET>,norm=<UNSET>,offset_transform=<UNSET>,offsets=<UNSET>,path_effects=<UNSET>,paths=<UNSET>,picker=<UNSET>,pickradius=<UNSET>,rasterized=<UNSET>,sketch_params=<UNSET>,snap=<UNSET>,transform=<UNSET>,url=<UNSET>,urls=<UNSET>,visible=<UNSET>,zorder=<UNSET>)[source]#
Set multiple properties at once.
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
array-like or float or None
bool
bool or list of bools
array-like or None
CapStyleor {'butt', 'projecting', 'round'}(vmin: float, vmax: float)
BboxBaseor Nonebool
Patch or (Path, Transform) or None
Colormapor str or Nonecolor or list of RGBA tuples
edgecolororecoredgecolorsfacecolororfacecolorsorfcstr
{'/', '\', '|', '-', '+', 'x', 'o', 'O', '.', '*'}
unknown
bool
JoinStyleor {'miter', 'round', 'bevel'}object
linestyleordashesorlinestylesorlsstr or tuple or list thereof
linewidthorlinewidthsorlwfloat or list of floats
bool
Normalizeor str or None(N, 2) or (2,) array-like
list of
AbstractPathEffectunknown
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