classmatplotlib.contour.ContourLabeler[source]
 
Bases: object Mixin to provide labelling capability to ContourSet.   add_label(x, y, rotation, lev, cvalue)[source]
 
Add contour label using Text class. 
   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).  Parameters 
 
x, yfloat


The approximate location of the label.  
inlinebool, default: True


If True remove the segment of the contour beneath the label.  
inline_spacingint, 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 the contour is straight, less so for labels on curved contours.  
transformTransform 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.     
   calc_label_rot_and_inline(slc, ind, lw, lc=None, spacing=5)[source]
 
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. 
   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 from this mixin class).  Parameters 
 
levelsarray-like, optional


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.  
fontsizestr or float, default: 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.  
colorscolor or colors or None, default: None


The label colors:  If None, the color of each label matches the color of the corresponding contour. If one string color, e.g., colors = 'r' or colors = 'red', all labels will be plotted in this color. If a tuple of colors (string, float, rgb, etc), different labels will be plotted in different colors in the order specified.   
inlinebool, default: True


If True the underlying contour is removed where the label is placed.  
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 the contour is straight, less so for labels on curved contours.  
fmtFormatter or str or callable or dict, optional


How the levels are formatted:  If a Formatter, it is used to format all levels at once, using its Formatter.format_ticks method. If a str, it is interpreted as a %-style format string. If a callable, it is called with one level at a time and should return 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 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.  
rightside_upbool, default: True


If True, label rotations will always be plus or minus 90 degrees from level.  
use_clabeltextbool, default: False


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.  
zorderfloat or None, default: (2 + contour.get_zorder())


zorder of the contour labels.    Returns 
 labels

A list of Text instances for the labels.     
   get_label_coords(distances, XX, YY, ysize, lw)[source]
 
[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. Notes  Deprecated since version 3.4.  
   get_label_width(lev, fmt, fsize)[source]
 
[Deprecated] Return the width of the label in points. Notes  Deprecated since version 3.5.  
   get_text(lev, fmt)[source]
 
Get the text of the label. 
   labels(inline, inline_spacing)[source]

   locate_label(linecontour, labelwidth)[source]
 
Find good place to draw a label (relatively flat part of the contour). 
   pop_label(index=- 1)[source]
 
Defaults to removing last label, but any index can be supplied 
   print_label(linecontour, labelwidth)[source]
 
Return whether a contour is long enough to hold a label. 
   set_label_props(label, text, color)[source]
 
Set the label properties - color, fontsize, text. 
   too_close(x, y, lw)[source]
 
Return whether a label is already near this location.