matplotlib.contour
¶These are classes to support contour plotting and labelling for the Axes class.
matplotlib.contour.
ClabelText
(x=0, y=0, text='', color=None, verticalalignment='baseline', horizontalalignment='left', multialignment=None, fontproperties=None, rotation=None, linespacing=None, rotation_mode=None, usetex=None, wrap=False, **kwargs)¶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 kwargs are
Property Description agg_filter
a filter function, which takes a (m, n, 3) float array and a dpi value, and returns a (m, n, 3) array alpha
float (0.0 transparent through 1.0 opaque) animated
bool backgroundcolor
any matplotlib color bbox
FancyBboxPatch prop dict clip_box
a matplotlib.transforms.Bbox
instanceclip_on
bool clip_path
[ ( Path
,Transform
) |Patch
| None ]color
any matplotlib color contains
a callable function family
or fontfamily or fontname or name[FONTNAME | ‘serif’ | ‘sans-serif’ | ‘cursive’ | ‘fantasy’ | ‘monospace’ ] figure
a Figure
instancefontproperties
or font_propertiesa matplotlib.font_manager.FontProperties
instancegid
an id string horizontalalignment
or ha[ ‘center’ | ‘right’ | ‘left’ ] label
object linespacing
float (multiple of font size) multialignment
or ma[‘left’ | ‘right’ | ‘center’ ] path_effects
AbstractPathEffect
picker
[None | bool | float | callable] position
(x,y) rasterized
bool or None rotation
[ angle in degrees | ‘vertical’ | ‘horizontal’ ] rotation_mode
[ None | “default” | “anchor” ] size
or fontsize[size in points | ‘xx-small’ | ‘x-small’ | ‘small’ | ‘medium’ | ‘large’ | ‘x-large’ | ‘xx-large’ ] sketch_params
(scale: float, length: float, randomness: float) snap
bool or None stretch
or fontstretch[a numeric value in range 0-1000 | ‘ultra-condensed’ | ‘extra-condensed’ | ‘condensed’ | ‘semi-condensed’ | ‘normal’ | ‘semi-expanded’ | ‘expanded’ | ‘extra-expanded’ | ‘ultra-expanded’ ] style
or fontstyle[ ‘normal’ | ‘italic’ | ‘oblique’] text
string or anything printable with ‘%s’ conversion. transform
Transform
url
a url string usetex
bool or None variant
or fontvariant[ ‘normal’ | ‘small-caps’ ] verticalalignment
or va[ ‘center’ | ‘top’ | ‘bottom’ | ‘baseline’ ] visible
bool weight
or fontweight[a numeric value in range 0-1000 | ‘ultralight’ | ‘light’ | ‘normal’ | ‘regular’ | ‘book’ | ‘medium’ | ‘roman’ | ‘semibold’ | ‘demibold’ | ‘demi’ | ‘bold’ | ‘heavy’ | ‘extra bold’ | ‘black’ ] wrap
bool x
float y
float zorder
float
get_rotation
()¶matplotlib.contour.
ContourLabeler
¶Bases: object
Mixin to provide labelling capability to ContourSet
add_label_clabeltext
(x, y, rotation, lev, cvalue)¶Add contour label using ClabelText
class.
add_label_near
(x, y, inline=True, inline_spacing=5, transform=None)¶Add a label near the point (x, y). If transform is None (default), (x, y) is in data coordinates; if transform is False, (x, y) is in display coordinates; otherwise, the specified transform will be used to translate (x, y) into display coordinates.
calc_label_rot_and_inline
(slc, ind, lw, lc=None, spacing=5)¶This function calculates the appropriate label rotation given the linecontour coordinates in screen units, the index of the label location and the label width.
It will also break contour and calculate inlining if lc is not empty (lc defaults to the empty list if None). spacing is the space around the label in pixels to leave empty.
Do both of these tasks at once to avoid calling mlab.path_length multiple times, which is relatively costly.
The method used here involves calculating 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.
clabel
(*args, **kwargs)¶Label a contour plot.
Call signature:
clabel(cs, **kwargs)
Adds labels to line contours in cs, where cs is a
ContourSet
object returned by
contour.
clabel(cs, v, **kwargs)
only labels contours listed in v.
Parameters: | fontsize : string or float, optional
colors :
inline : bool, optional
inline_spacing : float, optional
fmt : string or dict, optional
manual : bool or iterable, optional
rightside_up : bool, optional
use_clabeltext : bool, optional
|
---|
get_label_coords
(distances, XX, YY, ysize, lw)¶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.
get_label_width
(lev, fmt, fsize)¶Return the width of the label in points.
get_real_label_width
(lev, fmt, fsize)¶Deprecated since version 2.2: The get_real_label_width function was deprecated in version 2.2.
This computes actual onscreen label width. This uses some black magic to determine onscreen extent of non-drawn label. This magic may not be very robust.
This method is not being used, and may be modified or removed.
get_text
(lev, fmt)¶get the text of the label
labels
(inline, inline_spacing)¶locate_label
(linecontour, labelwidth)¶Find good place to draw a label (relatively flat part of the contour).
pop_label
(index=-1)¶Defaults to removing last label, but any index can be supplied
print_label
(linecontour, labelwidth)¶Return False if contours are too short for a label.
set_label_props
(label, text, color)¶set the label properties - color, fontsize, text
too_close
(x, y, lw)¶Return True if a label is already near this location.
matplotlib.contour.
ContourSet
(ax, *args, **kwargs)¶Bases: matplotlib.cm.ScalarMappable
, matplotlib.contour.ContourLabeler
Store a set of contour lines or filled regions.
User-callable method: clabel
Attributes
ax: | The axes object in which the contours are drawn. |
collections: | A silent_list of LineCollections or PolyCollections. |
levels: | Contour levels. |
layers: | Same as levels for line contours; half-way between levels for filled contours. See _process_colors() . |
Draw contour lines or filled regions, depending on
whether keyword arg filled is False
(default) or True
.
The first three arguments must be:
ax: axes object.
- 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 the levels. For contour lines
len(allsegs) == len(levels)
, and for filled contour regionslen(allsegs) = len(levels)-1
. The lists should look like:level0segs = [polygon0, polygon1, ...] polygon0 = array_like [[x0,y0], [x1,y1], ...]- allkinds: 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 thatlevel0segs = [polygon0]
andlevel0kinds = [polygon0kinds]
.
Keyword arguments are as described in the docstring of
contour
.
changed
()¶find_nearest_contour
(x, y, indices=None, pixel=True)¶Finds contour that is closest to a point. Defaults to measuring distance in pixels (screen space - useful for manual contour labeling), but this can be controlled via a keyword argument.
Returns a tuple containing the contour, segment, index of segment, x & y of segment point and distance to minimum point.
Optional keyword arguments:
- indices:
- Indexes of contour levels to consider when looking for nearest point. Defaults to using all levels.
- pixel:
- If True, measure distance in pixel space, if not, measure distance in axes space. Defaults to True.
get_alpha
()¶returns alpha to be applied to all ContourSet artists
legend_elements
(variable_name='x', str_format=<class 'str'>)¶Return a list of artist and labels suitable for passing through
to plt.legend()
which represent this ContourSet.
Args:
- variable_name: the string used inside the inequality used
- on the labels
str_format: function used to format the numbers in the labels
set_alpha
(alpha)¶sets alpha for all ContourSet artists
matplotlib.contour.
QuadContourSet
(ax, *args, **kwargs)¶Bases: matplotlib.contour.ContourSet
Create and store a set of contour lines or filled regions.
User-callable method: clabel()
Attributes
ax: | The axes object in which the contours are drawn. |
collections: | A silent_list of LineCollections or PolyCollections. |
levels: | Contour levels. |
layers: | Same as levels for line contours; half-way between levels for filled contours. See _process_colors() method. |
Draw contour lines or filled regions, depending on
whether keyword arg filled is False
(default) or True
.
The first three arguments must be:
ax: axes object.
- 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 the levels. For contour lines
len(allsegs) == len(levels)
, and for filled contour regionslen(allsegs) = len(levels)-1
. The lists should look like:level0segs = [polygon0, polygon1, ...] polygon0 = array_like [[x0,y0], [x1,y1], ...]- allkinds: 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 thatlevel0segs = [polygon0]
andlevel0kinds = [polygon0kinds]
.
Keyword arguments are as described in the docstring of
contour
.