matplotlib.text¶Classes for including text in a figure.
matplotlib.text.Annotation(s, xy, xytext=None, xycoords='data', textcoords=None, arrowprops=None, annotation_clip=None, **kwargs)[source]¶Bases: matplotlib.text.Text, matplotlib.text._AnnotationBase
An Annotation is a Text that can refer to a specific position xy.
Optionally an arrow pointing from the text to xy can be drawn.
| Attributes: |
|
|---|
Annotate the point xy with text s.
In the simplest form, the text is placed at xy.
Optionally, the text can be displayed in another position xytext. An arrow pointing from the text to the annotated point xy can then be added by defining arrowprops.
| Parameters: |
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Returns: |
|
See also
anncoords¶The coordinate system to use for Annotation.xyann.
arrow¶Deprecated since version 3.0: arrow was deprecated in Matplotlib 3.0 and will be removed in 3.2. Use arrow_patch instead.
contains(event)[source]¶Test whether the mouse event occurred in the patch.
In the case of text, a hit is true anywhere in the axis-aligned bounding-box containing the text.
| Returns: |
|
|---|
draw(renderer)[source]¶Draw the Annotation object to the given renderer.
get_anncoords()¶Return the coordinate system to use for Annotation.xyann.
See also xycoords in Annotation.
get_window_extent(renderer=None)[source]¶Return the Bbox bounding the text and arrow, in display units.
| Parameters: |
|
|---|
set_anncoords(coords)¶Set the coordinate system to use for Annotation.xyann.
See also xycoords in Annotation.
xyann¶The the text position.
See also xytext in Annotation.
matplotlib.text.OffsetFrom(artist, ref_coord, unit='points')[source]¶Bases: object
Callable helper class for working with Annotation
| Parameters: |
|
|---|
matplotlib.text.Text(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.artist.Artist
Handle storing and drawing of text in window or data coordinates.
Create a Text instance at x, y with string text.
Valid kwargs are
Property Description agg_filtera filter function, which takes a (m, n, 3) float array and a dpi value, and returns a (m, n, 3) array alphafloat animatedbool backgroundcolorcolor bboxdict with properties for patches.FancyBboxPatchclip_boxmatplotlib.transforms.Bboxclip_onbool clip_path{ ( path.Path,transforms.Transform),patches.Patch, None }colorcolor containscallable figureFigurefontfamily{FONTNAME, 'serif', 'sans-serif', 'cursive', 'fantasy', 'monospace'} fontname{FONTNAME, 'serif', 'sans-serif', 'cursive', 'fantasy', 'monospace'} fontpropertiesfont_manager.FontPropertiesfontsize{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'} gidstr horizontalalignment{'center', 'right', 'left'} in_layoutbool labelobject linespacingfloat (multiple of font size) multialignment{'left', 'right', 'center'} path_effectsAbstractPathEffectpickerNone or bool or float or callable position(float, float) rasterizedbool or None rotation{angle in degrees, 'vertical', 'horizontal'} rotation_mode{None, 'default', 'anchor'} sketch_params(scale: float, length: float, randomness: float) snapbool or None textstring or object castable to string (but Nonebecomes'')transformTransformurlstr usetexbool or None verticalalignment{'center', 'top', 'bottom', 'baseline', 'center_baseline'} visiblebool wrapbool xfloat yfloat zorderfloat
contains(mouseevent)[source]¶Test whether the mouse event occurred in the patch.
In the case of text, a hit is true anywhere in the axis-aligned bounding-box containing the text.
| Returns: |
|
|---|
get_bbox_patch()[source]¶Return the bbox Patch, or None if the patches.FancyBboxPatch
is not made.
get_family(*args, **kwargs)¶alias for get_fontfamily
get_font_properties(*args, **kwargs)¶alias for get_fontproperties
get_fontproperties()[source]¶Return the font_manager.FontProperties object
get_ha(*args, **kwargs)¶alias for get_horizontalalignment
get_horizontalalignment()[source]¶Return the horizontal alignment as string. Will be one of 'left', 'center' or 'right'.
get_name(*args, **kwargs)¶alias for get_fontname
get_prop_tup(renderer=None)[source]¶Return a hashable tuple of properties.
Not intended to be human readable, but useful for backends who want to cache derived information about text (e.g., layouts) and need to know if the text has changed.
get_size(*args, **kwargs)¶alias for get_fontsize
get_style(*args, **kwargs)¶alias for get_fontstyle
get_usetex()[source]¶Return whether this Text object uses TeX for rendering.
If the user has not manually set this value, it defaults to
rcParams["text.usetex"].
get_va(*args, **kwargs)¶alias for get_verticalalignment
get_variant(*args, **kwargs)¶alias for get_fontvariant
get_verticalalignment()[source]¶Return the vertical alignment as string. Will be one of 'top', 'center', 'bottom' or 'baseline'.
get_weight(*args, **kwargs)¶alias for get_fontweight
get_window_extent(renderer=None, dpi=None)[source]¶Return the Bbox bounding the text, in display units.
In addition to being used internally, this is useful for specifying clickable regions in a png file on a web page.
| Parameters: |
|
|---|
is_math_text(s, usetex=None)[source]¶Returns a cleaned string and a boolean flag. The flag indicates if the given string s contains any mathtext, determined by counting unescaped dollar signs. If no mathtext is present, the cleaned string has its dollar signs unescaped. If usetex is on, the flag always has the value "TeX".
set_backgroundcolor(color)[source]¶Set the background color of the text by updating the bbox.
| Parameters: |
|
|---|
See also
set_bboxset_bbox(rectprops)[source]¶Draw a bounding box around self.
| Parameters: |
|
|---|
Examples
t.set_bbox(dict(facecolor='red', alpha=0.5))
set_clip_box(clipbox)[source]¶Set the artist's clip Bbox.
| Parameters: |
|
|---|
set_clip_on(b)[source]¶Set whether artist uses clipping.
When False, artists will be visible outside of the axes, which can lead to unexpected results.
| Parameters: |
|
|---|
set_clip_path(path, transform=None)[source]¶Set the artist's clip path, which may be:
For efficiency, if the path happens to be an axis-aligned rectangle, this method will set the clipping box to the corresponding rectangle and set the clipping path to None.
path.Path, transforms.Transform),patches.Patch, None }set_family(*args, **kwargs)¶alias for set_fontfamily
set_font_properties(*args, **kwargs)¶alias for set_fontproperties
set_fontfamily(fontname)[source]¶Set the font family. May be either a single string, or a list of strings in decreasing priority. Each string may be either a real font name or a generic font class name. If the latter, the specific font names will be looked up in the corresponding rcParams.
| Parameters: |
|
|---|
set_fontname(fontname)[source]¶alias for set_family
One-way alias only: the getter differs.
| Parameters: |
|
|---|
set_fontsize(fontsize)[source]¶Set the font size. May be either a size string, relative to the default font size, or an absolute font size in points.
| Parameters: |
|
|---|
See also
set_fontstretch(stretch)[source]¶Set the font stretch (horizontal condensation or expansion).
| Parameters: |
|
|---|
set_fontstyle(fontstyle)[source]¶Set the font style.
| Parameters: |
|
|---|
set_fontvariant(variant)[source]¶Set the font variant, either 'normal' or 'small-caps'.
| Parameters: |
|
|---|
set_fontweight(weight)[source]¶Set the font weight.
| Parameters: |
|
|---|
set_ha(*args, **kwargs)¶alias for set_horizontalalignment
set_horizontalalignment(align)[source]¶Set the horizontal alignment to one of
| Parameters: |
|
|---|
set_linespacing(spacing)[source]¶Set the line spacing as a multiple of the font size. Default is 1.2.
| Parameters: |
|
|---|
set_ma(*args, **kwargs)¶alias for set_multialignment
set_multialignment(align)[source]¶Set the alignment for multiple lines layout. The layout of the bounding box of all the lines is determined bu the horizontalalignment and verticalalignment properties, but the multiline text within that box can be
| Parameters: |
|
|---|
set_name(*args, **kwargs)¶alias for set_fontname
set_rotation(s)[source]¶Set the rotation of the text.
| Parameters: |
|
|---|
set_rotation_mode(m)[source]¶Set text rotation mode.
| Parameters: |
|
|---|
set_size(*args, **kwargs)¶alias for set_fontsize
set_stretch(*args, **kwargs)¶alias for set_fontstretch
set_style(*args, **kwargs)¶alias for set_fontstyle
set_text(s)[source]¶Set the text string s.
It may contain newlines (\n) or math in LaTeX syntax.
| Parameters: |
|
|---|
set_usetex(usetex)[source]¶| Parameters: |
|
|---|
set_va(*args, **kwargs)¶alias for set_verticalalignment
set_variant(*args, **kwargs)¶alias for set_fontvariant
set_verticalalignment(align)[source]¶Set the vertical alignment
| Parameters: |
|
|---|
set_weight(*args, **kwargs)¶alias for set_fontweight
update_bbox_position_size(renderer)[source]¶Update the location and the size of the bbox.
This method should be used when the position and size of the bbox needs to be updated before actually drawing the bbox.
zorder = 3¶matplotlib.text.TextWithDash(x=0, y=0, text='', color=None, verticalalignment='center', horizontalalignment='center', multialignment=None, fontproperties=None, rotation=None, linespacing=None, dashlength=0.0, dashdirection=0, dashrotation=None, dashpad=3, dashpush=0)[source]¶Bases: matplotlib.text.Text
This is basically a Text with a dash
(drawn with a Line2D) before/after
it. It is intended to be a drop-in replacement for
Text, and should behave identically to
it when dashlength = 0.0.
The dash always comes between the point specified by
set_position() and the text. When a
dash exists, the text alignment arguments (horizontalalignment,
verticalalignment) are ignored.
dashlength is the length of the dash in canvas units. (default = 0.0).
dashdirection is one of 0 or 1, where 0 draws the dash after the text and 1 before. (default = 0).
dashrotation specifies the rotation of the dash, and should
generally stay None. In this case
get_dashrotation() returns
get_rotation(). (i.e., the dash takes
its rotation from the text's rotation). Because the text center is
projected onto the dash, major deviations in the rotation cause
what may be considered visually unappealing results.
(default = None)
dashpad is a padding length to add (or subtract) space between the text and the dash, in canvas units. (default = 3)
dashpush "pushes" the dash and text away from the point
specified by set_position() by the
amount in canvas units. (default = 0)
Note
The alignment of the two objects is based on the bounding box
of the Text, as obtained by
get_window_extent(). This, in
turn, appears to depend on the font metrics as given by the
rendering backend. Hence the quality of the "centering" of the
label text with respect to the dash varies depending on the
backend used.
Note
I'm not sure that I got the
get_window_extent() right,
or whether that's sufficient for providing the object bounding
box.
draw(renderer)[source]¶Draw the TextWithDash object to the given renderer.
get_dashpush()[source]¶Get the extra spacing between the dash and the specified text position, in canvas units.
get_prop_tup(renderer=None)[source]¶Return a hashable tuple of properties.
Not intended to be human readable, but useful for backends who want to cache derived information about text (e.g., layouts) and need to know if the text has changed.
get_window_extent(renderer=None)[source]¶Return a Bbox object bounding
the text, in display units.
In addition to being used internally, this is useful for specifying clickable regions in a png file on a web page.
renderer defaults to the _renderer attribute of the text
object. This is not assigned until the first execution of
draw(), so you must use this kwarg if you want
to call get_window_extent() prior to the first
draw(). For getting web page regions, it is
simpler to call the method after saving the figure.
set_dashdirection(dd)[source]¶Set the direction of the dash following the text. 1 is before the text and 0 is after. The default is 0, which is what you'd want for the typical case of ticks below and on the left of the figure.
| Parameters: |
|
|---|
set_dashpad(dp)[source]¶Set the "pad" of the TextWithDash, which is the extra spacing between the dash and the text, in canvas units.
| Parameters: |
|
|---|
set_dashpush(dp)[source]¶Set the "push" of the TextWithDash, which is the extra spacing between the beginning of the dash and the specified position.
| Parameters: |
|
|---|
set_figure(fig)[source]¶Set the figure instance the artist belongs to.
| Parameters: |
|
|---|
set_position(xy)[source]¶Set the (x, y) position of the TextWithDash.
| Parameters: |
|
|---|
set_transform(t)[source]¶Set the matplotlib.transforms.Transform instance used
by this artist.
| Parameters: |
|
|---|
set_x(x)[source]¶Set the x position of the TextWithDash.
| Parameters: |
|
|---|
set_y(y)[source]¶Set the y position of the TextWithDash.
| Parameters: |
|
|---|