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)[source]¶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 animated
bool backgroundcolor
color bbox
dict with properties for patches.FancyBboxPatch
clip_box
matplotlib.transforms.Bbox
clip_on
bool clip_path
{ ( path.Path
,transforms.Transform
),patches.Patch
, None }color
color contains
callable figure
Figure
fontfamily
{FONTNAME, 'serif', 'sans-serif', 'cursive', 'fantasy', 'monospace'} fontname
{FONTNAME, 'serif', 'sans-serif', 'cursive', 'fantasy', 'monospace'} fontproperties
font_manager.FontProperties
fontsize
{size in points, 'xx-small', 'x-small', 'small', 'medium', 'large', 'x-large', 'xx-large'} fontstretch
{a numeric value in range 0-1000, 'ultra-condensed', 'extra-condensed', 'condensed', 'semi-condensed', 'normal', 'semi-expanded', 'expanded', 'extra-expanded', 'ultra-expanded'} fontstyle
{'normal', 'italic', 'oblique'} fontvariant
{'normal', 'small-caps'} fontweight
{a numeric value in range 0-1000, 'ultralight', 'light', 'normal', 'regular', 'book', 'medium', 'roman', 'semibold', 'demibold', 'demi', 'bold', 'heavy', 'extra bold', 'black'} gid
str horizontalalignment
{'center', 'right', 'left'} in_layout
bool label
object linespacing
float (multiple of font size) multialignment
{'left', 'right', 'center'} path_effects
AbstractPathEffect
picker
None or bool or float or callable position
(float, float) rasterized
bool or None rotation
{angle in degrees, 'vertical', 'horizontal'} rotation_mode
{None, 'default', 'anchor'} sketch_params
(scale: float, length: float, randomness: float) snap
bool or None text
string or object castable to string (but None
becomes''
)transform
Transform
url
str usetex
bool or None verticalalignment
{'center', 'top', 'bottom', 'baseline', 'center_baseline'} visible
bool wrap
bool x
float y
float zorder
float
matplotlib.contour.
ContourLabeler
[source]¶Bases: object
Mixin to provide labelling capability to ContourSet
.
add_label_clabeltext
(x, y, rotation, lev, cvalue)[source]¶Add contour label using ClabelText
class.
add_label_near
(x, y, inline=True, inline_spacing=5, transform=None)[source]¶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.
Parameters: |
|
---|
calc_label_rot_and_inline
(slc, ind, lw, lc=None, spacing=5)[source]¶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 calculating path lengths 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.
cl
¶Deprecated since version 3.0: The <lambda> function was deprecated in Matplotlib 3.0 and will be removed in 3.2. Use labelTexts instead.
cl_cvalues
¶Deprecated since version 3.0: The <lambda> function was deprecated in Matplotlib 3.0 and will be removed in 3.2. Use labelCValues instead.
cl_xy
¶Deprecated since version 3.0: The <lambda> function was deprecated in Matplotlib 3.0 and will be removed in 3.2. Use labelXYs instead.
clabel
(*args, fontsize=None, inline=True, inline_spacing=5, fmt='%1.3f', colors=None, use_clabeltext=False, manual=False, rightside_up=True)[source]¶Label a contour plot.
Call signature:
clabel(cs, [levels,] **kwargs)
Adds labels to line contours in cs, where cs is a
ContourSet
object returned by
contour()
.
Parameters: |
|
---|---|
Returns: |
|
get_label_coords
(distances, XX, YY, ysize, lw)[source]¶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_real_label_width
(lev, fmt, fsize)[source]¶Deprecated since version 2.2: The get_real_label_width function was deprecated in Matplotlib 2.2 and will be removed in 3.1.
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.
matplotlib.contour.
ContourSet
(ax, *args, levels=None, filled=False, linewidths=None, linestyles=None, alpha=None, origin=None, extent=None, cmap=None, colors=None, norm=None, vmin=None, vmax=None, extend='neither', antialiased=None, **kwargs)[source]¶Bases: matplotlib.cm.ScalarMappable
, matplotlib.contour.ContourLabeler
Store a set of contour lines or filled regions.
User-callable method: clabel
Parameters: |
|
---|---|
Attributes: |
|
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)
Parameters: |
|
---|
changed
()[source]¶Call this whenever the mappable is changed to notify all the callbackSM listeners to the 'changed' signal
find_nearest_contour
(x, y, indices=None, pixel=True)[source]¶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.
legend_elements
(variable_name='x', str_format=<class 'str'>)[source]¶Return a list of artists and labels suitable for passing through
to plt.legend()
which represent this ContourSet.
The labels have the form "0 < x <= 1" stating the data ranges which the artists represent.
Parameters: |
|
---|---|
Returns: |
|
matplotlib.contour.
QuadContourSet
(ax, *args, levels=None, filled=False, linewidths=None, linestyles=None, alpha=None, origin=None, extent=None, cmap=None, colors=None, norm=None, vmin=None, vmax=None, extend='neither', antialiased=None, **kwargs)[source]¶Bases: matplotlib.contour.ContourSet
Create and store a set of contour lines or filled regions.
User-callable method: clabel
Attributes: |
|
---|
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)
Parameters: |
|
---|