Classes to support contour plotting and labelling for the Axes class.
Bases: matplotlib.text.Text
Unlike the ordinary text, the get_rotation returns an updated angle in the pixel coordinate assuming that the input rotation is an angle in data coordinate (or whatever transform set).
Create a Text
instance at x, y with string text.
Valid keyword arguments 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 | |
scalar or None | |
bool | |
color | |
dict with properties for | |
unknown | |
unknown | |
unknown | |
| color |
| {FONTNAME, 'serif', 'sans-serif', 'cursive', 'fantasy', 'monospace'} |
| |
| float or {'xx-small', 'x-small', 'small', 'medium', 'large', 'x-large', 'xx-large'} |
| {a numeric value in range 0-1000, 'ultra-condensed', 'extra-condensed', 'condensed', 'semi-condensed', 'normal', 'semi-expanded', 'expanded', 'extra-expanded', 'ultra-expanded'} |
| {'normal', 'italic', 'oblique'} |
| {'normal', 'small-caps'} |
| {a numeric value in range 0-1000, 'ultralight', 'light', 'normal', 'regular', 'book', 'medium', 'roman', 'semibold', 'demibold', 'demi', 'bold', 'heavy', 'extra bold', 'black'} |
str | |
| {'center', 'right', 'left'} |
bool | |
object | |
float (multiple of font size) | |
str | |
| {'left', 'right', 'center'} |
bool | |
None or bool or float or callable | |
(float, float) | |
bool | |
float or {'vertical', 'horizontal'} | |
{None, 'default', 'anchor'} | |
(scale: float, length: float, randomness: float) | |
bool or None | |
object | |
bool | |
str | |
bool or None | |
| {'center', 'top', 'bottom', 'baseline', 'center_baseline'} |
bool | |
bool | |
float | |
float | |
float |
Return the text angle in degrees between 0 and 360.
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 | |
scalar or None | |
bool | |
color | |
dict with properties for | |
bool | |
Patch or (Path, Transform) or None | |
| color |
| {FONTNAME, 'serif', 'sans-serif', 'cursive', 'fantasy', 'monospace'} |
| |
| float or {'xx-small', 'x-small', 'small', 'medium', 'large', 'x-large', 'xx-large'} |
| {a numeric value in range 0-1000, 'ultra-condensed', 'extra-condensed', 'condensed', 'semi-condensed', 'normal', 'semi-expanded', 'expanded', 'extra-expanded', 'ultra-expanded'} |
| {'normal', 'italic', 'oblique'} |
| {'normal', 'small-caps'} |
| {a numeric value in range 0-1000, 'ultralight', 'light', 'normal', 'regular', 'book', 'medium', 'roman', 'semibold', 'demibold', 'demi', 'bold', 'heavy', 'extra bold', 'black'} |
str | |
| {'center', 'right', 'left'} |
bool | |
object | |
float (multiple of font size) | |
str | |
| {'left', 'right', 'center'} |
bool | |
None or bool or float or callable | |
(float, float) | |
bool | |
float or {'vertical', 'horizontal'} | |
{None, 'default', 'anchor'} | |
(scale: float, length: float, randomness: float) | |
bool or None | |
object | |
bool | |
str | |
bool or None | |
| {'center', 'top', 'bottom', 'baseline', 'center_baseline'} |
bool | |
bool | |
float | |
float | |
float |
Bases: object
Mixin to provide labelling capability to ContourSet
.
Add contour label using ClabelText
class.
Add a label near the point (x, y)
.
The approximate location of the label.
If True remove the segment of the contour beneath the label.
Space in pixels to leave on each side of label when placing inline. This spacing will be exact for labels at locations where the contour is straight, less so for labels on curved contours.
Transform
or False
, default: self.axes.transData
A transform applied to (x, y)
before labeling. The default causes (x, y)
to be interpreted as data coordinates. False
is a synonym for IdentityTransform
; i.e. (x, y)
should be interpreted as display coordinates.
Calculate the appropriate label rotation given the linecontour coordinates in screen units, the index of the label location and the label width.
If lc is not None or empty, also break contours and compute inlining.
spacing is the empty space to leave around the label, in pixels.
Both tasks are done together to avoid calculating path lengths multiple times, which is relatively costly.
The method used here involves computing the path length along the contour in pixel coordinates and then looking approximately (label width / 2) away from central point to determine rotation and then to break contour if desired.
Label a contour plot.
Adds labels to line contours in this ContourSet
(which inherits from this mixin class).
A list of level values, that should be labeled. The list must be a subset of cs.levels
. If not given, all levels are labeled.
rcParams["font.size"]
(default: 10.0
)
Size in points or relative size e.g., 'smaller', 'x-large'. See Text.set_size
for accepted string values.
The label colors:
If True
the underlying contour is removed where the label is placed.
Space in pixels to leave on each side of label when placing inline.
This spacing will be exact for labels at locations where the contour is straight, less so for labels on curved contours.
Formatter
or str or callable or dict, optional
How the levels are formatted:
Formatter
, it is used to format all levels at once, using its Formatter.format_ticks
method.The default is to use a standard ScalarFormatter
.
If True
, contour labels will be placed manually using mouse clicks. Click the first button near a contour to add a label, click the second button (or potentially both mouse buttons at once) to finish adding labels. The third button can be used to remove the last label added, but only if labels are not inline. Alternatively, the keyboard can be used to select label locations (enter to end label placement, 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.
If True
, label rotations will always be plus or minus 90 degrees from level.
If True
, ClabelText
class (instead of Text
) is used to create labels. ClabelText
recalculates rotation angles of texts during the drawing time, therefore this can be used if aspect of the axes changes.
(2 + contour.get_zorder())
zorder of the contour labels.
A list of Text
instances for the labels.
[Deprecated] Return x, y, and the index of a label location.
Labels are plotted at a location with the smallest deviation of the contour from a straight line unless there is another label nearby, in which case the next best place on the contour is picked up. If all such candidates are rejected, the beginning of the contour is chosen.
Deprecated since version 3.4.
[Deprecated] Return the width of the label in points.
Deprecated since version 3.5.
Get the text of the label.
Find good place to draw a label (relatively flat part of the contour).
Defaults to removing last label, but any index can be supplied
Return whether a contour is long enough to hold a label.
Set the label properties - color, fontsize, text.
Return whether a label is already near this location.
Bases: matplotlib.cm.ScalarMappable
, matplotlib.contour.ContourLabeler
Store a set of contour lines or filled regions.
User-callable method: clabel
Axes
A list of floating point numbers indicating the contour levels.
List of all the polygon segments for all the levels. For contour lines len(allsegs) == len(levels)
, and for filled contour regions len(allsegs) = len(levels)-1
. The lists should look like
level0segs = [polygon0, polygon1, ...] polygon0 = [[x0, y0], [x1, y1], ...]
None
or [level0kinds, level1kinds, ...]
Optional list of all the polygon vertex kinds (code types), as described 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 lists should look like
level0kinds = [polygon0kinds, ...] polygon0kinds = [vertexcode0, vertexcode1, ...]
If allkinds is not None
, usually all polygons for a particular contour level are grouped together so that level0segs = [polygon0]
and level0kinds = [polygon0kinds]
.
Keyword arguments are as described in the docstring of contour
.
Axes
The Axes object in which the contours are drawn.
silent_list
of PathCollection
s
The Artist
s representing the contour. This is a list of PathCollection
s for both line and filled contours.
The values of the contour levels.
Same as levels for line contours; half-way between levels for filled contours. See ContourSet._process_colors
.
Draw contour lines or filled regions, depending on whether keyword arg filled is False
(default) or True
.
Call signature:
ContourSet(ax, levels, allsegs, [allkinds], **kwargs)
Axes
The Axes
object to draw on.
A list of floating point numbers indicating the contour levels.
List of all the polygon segments for all the levels. For contour lines len(allsegs) == len(levels)
, and for filled contour regions len(allsegs) = len(levels)-1
. The lists should look like
level0segs = [polygon0, polygon1, ...] polygon0 = [[x0, y0], [x1, y1], ...]
Optional list of all the polygon vertex kinds (code types), as described 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 lists should look like
level0kinds = [polygon0kinds, ...] polygon0kinds = [vertexcode0, vertexcode1, ...]
If allkinds is not None
, usually all polygons for a particular contour level are grouped together so that level0segs = [polygon0]
and level0kinds = [polygon0kinds]
.
Keyword arguments are as described in the docstring of contour
.
Call this whenever the mappable is changed to notify all the callbackSM listeners to the 'changed' signal.
Find the point in the contour plot that is closest to (x, y)
.
The reference point.
Indices of contour levels to consider. If None (the default), all levels are considered.
If True, measure distance in pixel (screen) space, which is useful for manual contour labeling; else, measure distance in axes space.
Collection
The contour that is closest to (x, y)
.
The index of the Path
in contour that is closest to (x, y)
.
The index of the path segment in segment that is closest to (x, y)
.
The point in the contour plot that is closest to (x, y)
.
The squared distance from (xmin, ymin)
to (x, y)
.
Return alpha to be applied to all ContourSet artists.
Return a list of artists and labels suitable for passing through to legend
which represent this ContourSet.
The labels have the form "0 < x <= 1" stating the data ranges which the artists represent.
The string used inside the inequality used on the labels.
Function used to format the numbers in the labels.
Artist
]
A list of the artists.
A list of the labels.
Set the alpha blending value for all ContourSet artists. alpha must be between 0 (transparent) and 1 (opaque).
Bases: matplotlib.contour.ContourSet
Create and store a set of contour lines or filled regions.
This class is typically not instantiated directly by the user but by contour
and contourf
.
Axes
The Axes object in which the contours are drawn.
silent_list
of PathCollection
s
The Artist
s representing the contour. This is a list of PathCollection
s for both line and filled contours.
The values of the contour levels.
Same as levels for line contours; half-way between levels for filled contours. See ContourSet._process_colors
.
Draw contour lines or filled regions, depending on whether keyword arg filled is False
(default) or True
.
Call signature:
ContourSet(ax, levels, allsegs, [allkinds], **kwargs)
Axes
The Axes
object to draw on.
A list of floating point numbers indicating the contour levels.
List of all the polygon segments for all the levels. For contour lines len(allsegs) == len(levels)
, and for filled contour regions len(allsegs) = len(levels)-1
. The lists should look like
level0segs = [polygon0, polygon1, ...] polygon0 = [[x0, y0], [x1, y1], ...]
Optional list of all the polygon vertex kinds (code types), as described 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 lists should look like
level0kinds = [polygon0kinds, ...] polygon0kinds = [vertexcode0, vertexcode1, ...]
If allkinds is not None
, usually all polygons for a particular contour level are grouped together so that level0segs = [polygon0]
and level0kinds = [polygon0kinds]
.
Keyword arguments are as described in the docstring of contour
.
© 2012–2021 Matplotlib Development Team. All rights reserved.
Licensed under the Matplotlib License Agreement.
https://matplotlib.org/3.5.1/api/contour_api.html