smpl.plot.Annotation

class smpl.plot.Annotation(text, xy, xytext=None, xycoords='data', textcoords=None, arrowprops=None, annotation_clip=None, **kwargs)[source]

Bases: 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

xy

The annotated position.

xycoords

The coordinate system for xy.

arrow_patch

A .FancyArrowPatch to point from xytext to xy.

__init__(text, xy, xytext=None, xycoords='data', textcoords=None, arrowprops=None, annotation_clip=None, **kwargs)[source]

Annotate the point xy with text text.

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

textstr

The text of the annotation.

xy(float, float)

The point (x, y) to annotate. The coordinate system is determined by xycoords.

xytext(float, float), default: xy

The position (x, y) to place the text at. The coordinate system is determined by textcoords.

xycoords : str or .Artist or .Transform or callable or (float, float), default: ‘data’

The coordinate system that xy is given in. The following types of values are supported:

  • One of the following strings:

    Value

    Description

    ‘figure points’

    Points from the lower left of the figure

    ‘figure pixels’

    Pixels from the lower left of the figure

    ‘figure fraction’

    Fraction of figure from lower left

    ‘subfigure points’

    Points from the lower left of the subfigure

    ‘subfigure pixels’

    Pixels from the lower left of the subfigure

    ‘subfigure fraction’

    Fraction of subfigure from lower left

    ‘axes points’

    Points from lower left corner of axes

    ‘axes pixels’

    Pixels from lower left corner of axes

    ‘axes fraction’

    Fraction of axes from lower left

    ‘data’

    Use the coordinate system of the object being annotated (default)

    ‘polar’

    (theta, r) if not native ‘data’ coordinates

    Note that ‘subfigure pixels’ and ‘figure pixels’ are the same for the parent figure, so users who want code that is usable in a subfigure can use ‘subfigure pixels’.

  • An .Artist: xy is interpreted as a fraction of the artist’s ~matplotlib.transforms.Bbox. E.g. (0, 0) would be the lower left corner of the bounding box and (0.5, 1) would be the center top of the bounding box.

  • A .Transform to transform xy to screen coordinates.

  • A function with one of the following signatures:

    def transform(renderer) -> Bbox
    def transform(renderer) -> Transform
    

    where renderer is a .RendererBase subclass.

    The result of the function is interpreted like the .Artist and .Transform cases above.

  • A tuple (xcoords, ycoords) specifying separate coordinate systems for x and y. xcoords and ycoords must each be of one of the above described types.

See plotting-guide-annotation for more details.

textcoordsstr or .Artist or .Transform or callable or (float, float), default: value of xycoords

The coordinate system that xytext is given in.

All xycoords values are valid as well as the following strings:

Value

Description

‘offset points’

Offset (in points) from the xy value

‘offset pixels’

Offset (in pixels) from the xy value

arrowpropsdict, optional

The properties used to draw a .FancyArrowPatch arrow between the positions xy and xytext. Defaults to None, i.e. no arrow is drawn.

For historical reasons there are two different ways to specify arrows, “simple” and “fancy”:

Simple arrow:

If arrowprops does not contain the key ‘arrowstyle’ the allowed keys are:

Key

Description

width

The width of the arrow in points

headwidth

The width of the base of the arrow head in points

headlength

The length of the arrow head in points

shrink

Fraction of total length to shrink from both ends

?

Any key to matplotlib.patches.FancyArrowPatch

The arrow is attached to the edge of the text box, the exact position (corners or centers) depending on where it’s pointing to.

Fancy arrow:

This is used if ‘arrowstyle’ is provided in the arrowprops.

Valid keys are the following ~matplotlib.patches.FancyArrowPatch parameters:

Key

Description

arrowstyle

the arrow style

connectionstyle

the connection style

relpos

see below; default is (0.5, 0.5)

patchA

default is bounding box of the text

patchB

default is None

shrinkA

default is 2 points

shrinkB

default is 2 points

mutation_scale

default is text size (in points)

mutation_aspect

default is 1.

?

any key for matplotlib.patches.PathPatch

The exact starting point position of the arrow is defined by relpos. It’s a tuple of relative coordinates of the text box, where (0, 0) is the lower left corner and (1, 1) is the upper right corner. Values <0 and >1 are supported and specify points outside the text box. By default (0.5, 0.5) the starting point is centered in the text box.

annotation_clipbool or None, default: None

Whether to clip (i.e. not draw) the annotation when the annotation point xy is outside the axes area.

  • If True, the annotation will be clipped when xy is outside the axes.

  • If False, the annotation will always be drawn.

  • If None, the annotation will be clipped when xy is outside the axes and xycoords is ‘data’.

**kwargs

Additional kwargs are passed to ~matplotlib.text.Text.

Returns

.Annotation

See Also

plotting-guide-annotation

Methods

__init__(text, xy[, xytext, xycoords, ...])

Annotate the point xy with text text.

add_callback(func)

Add a callback function that will be called whenever one of the .Artist's properties changes.

contains(event)

Return whether the mouse event occurred inside the axis-aligned bounding-box of the text.

convert_xunits(x)

Convert x using the unit type of the xaxis.

convert_yunits(y)

Convert y using the unit type of the yaxis.

draggable([state, use_blit])

Set whether the annotation is draggable with the mouse.

draw(renderer)

Draw the Artist (and its children) using the given renderer.

findobj([match, include_self])

Find artist objects.

format_cursor_data(data)

Return a string representation of data.

get_agg_filter()

Return filter function to be used for agg filter.

get_alpha()

Return the alpha value used for blending - not supported on all backends.

get_animated()

Return whether the artist is animated.

get_anncoords()

Return the coordinate system to use for .Annotation.xyann.

get_annotation_clip()

Return the annotation's clipping behavior.

get_bbox_patch()

Return the bbox Patch, or None if the .patches.FancyBboxPatch is not made.

get_c()

Alias for get_color.

get_children()

Return a list of the child .Artists of this .Artist.

get_clip_box()

Return the clipbox.

get_clip_on()

Return whether the artist uses clipping.

get_clip_path()

Return the clip path.

get_color()

Return the color of the text.

get_cursor_data(event)

Return the cursor data for a given event.

get_family()

Alias for get_fontfamily.

get_figure()

Return the .Figure instance the artist belongs to.

get_font()

Alias for get_fontproperties.

get_font_properties()

Alias for get_fontproperties.

get_fontfamily()

Return the list of font families used for font lookup.

get_fontname()

Return the font name as a string.

get_fontproperties()

Return the .font_manager.FontProperties.

get_fontsize()

Return the font size as an integer.

get_fontstyle()

Return the font style as a string.

get_fontvariant()

Return the font variant as a string.

get_fontweight()

Return the font weight as a string or a number.

get_gid()

Return the group id.

get_ha()

Alias for get_horizontalalignment.

get_horizontalalignment()

Return the horizontal alignment as a string.

get_in_layout()

Return boolean flag, True if artist is included in layout calculations.

get_label()

Return the label used for this artist in the legend.

get_math_fontfamily()

Return the font family name for math text rendered by Matplotlib.

get_mouseover()

Return whether this artist is queried for custom context information when the mouse cursor moves over it.

get_name()

Alias for get_fontname.

get_parse_math()

Return whether mathtext parsing is considered for this Text.

get_path_effects()

get_picker()

Return the picking behavior of the artist.

get_position()

Return the (x, y) position of the text.

get_prop_tup([renderer])

[Deprecated] Return a hashable tuple of properties.

get_rasterized()

Return whether the artist is to be rasterized.

get_rotation()

Return the text angle in degrees between 0 and 360.

get_rotation_mode()

Return the text rotation mode.

get_size()

Alias for get_fontsize.

get_sketch_params()

Return the sketch parameters for the artist.

get_snap()

Return the snap setting.

get_stretch()

Return the font stretch as a string or a number.

get_style()

Alias for get_fontstyle.

get_text()

Return the text string.

get_tightbbox([renderer])

Like .Artist.get_window_extent, but includes any clipping.

get_transform()

Return the .Transform instance used by this artist.

get_transform_rotates_text()

Return whether rotations of the transform affect the text direction.

get_transformed_clip_path_and_affine()

Return the clip path with the non-affine part of its transformation applied, and the remaining affine part of its transformation.

get_unitless_position()

Return the (x, y) unitless position of the text.

get_url()

Return the url.

get_usetex()

Return whether this Text object uses TeX for rendering.

get_va()

Alias for get_verticalalignment.

get_variant()

Alias for get_fontvariant.

get_verticalalignment()

Return the vertical alignment as a string.

get_visible()

Return the visibility.

get_weight()

Alias for get_fontweight.

get_window_extent([renderer])

Return the .Bbox bounding the text, in display units.

get_wrap()

Return whether the text can be wrapped.

get_zorder()

Return the artist's zorder.

have_units()

Return whether units are set on any axis.

is_transform_set()

Return whether the Artist has an explicitly set transform.

pchanged()

Call all of the registered callbacks.

pick(mouseevent)

Process a pick event.

pickable()

Return whether the artist is pickable.

properties()

Return a dictionary of all the properties of the artist.

remove()

Remove the artist from the figure if possible.

remove_callback(oid)

Remove a callback based on its observer id.

set(*[, agg_filter, alpha, animated, ...])

Set multiple properties at once.

set_agg_filter(filter_func)

Set the agg filter.

set_alpha(alpha)

Set the alpha value used for blending - not supported on all backends.

set_animated(b)

Set whether the artist is intended to be used in an animation.

set_anncoords(coords)

Set the coordinate system to use for .Annotation.xyann.

set_annotation_clip(b)

Set the annotation's clipping behavior.

set_backgroundcolor(color)

Set the background color of the text by updating the bbox.

set_bbox(rectprops)

Draw a bounding box around self.

set_c(color)

Alias for set_color.

set_clip_box(clipbox)

Set the artist's clip .Bbox.

set_clip_on(b)

Set whether the artist uses clipping.

set_clip_path(path[, transform])

Set the artist's clip path.

set_color(color)

Set the foreground color of the text

set_family(fontname)

Alias for set_fontfamily.

set_figure(fig)

Set the .Figure instance the artist belongs to.

set_font(fp)

Alias for set_fontproperties.

set_font_properties(fp)

Alias for set_fontproperties.

set_fontfamily(fontname)

Set the font family.

set_fontname(fontname)

Alias for set_family.

set_fontproperties(fp)

Set the font properties that control the text.

set_fontsize(fontsize)

Set the font size.

set_fontstretch(stretch)

Set the font stretch (horizontal condensation or expansion).

set_fontstyle(fontstyle)

Set the font style.

set_fontvariant(variant)

Set the font variant.

set_fontweight(weight)

Set the font weight.

set_gid(gid)

Set the (group) id for the artist.

set_ha(align)

Alias for set_horizontalalignment.

set_horizontalalignment(align)

Set the horizontal alignment relative to the anchor point.

set_in_layout(in_layout)

Set if artist is to be included in layout calculations, E.g.

set_label(s)

Set a label that will be displayed in the legend.

set_linespacing(spacing)

Set the line spacing as a multiple of the font size.

set_ma(align)

Alias for set_multialignment.

set_math_fontfamily(fontfamily)

Set the font family for math text rendered by Matplotlib.

set_mouseover(mouseover)

Set whether this artist is queried for custom context information when the mouse cursor moves over it.

set_multialignment(align)

Set the text alignment for multiline texts.

set_name(fontname)

Alias for set_fontname.

set_parse_math(parse_math)

Override switch to disable any mathtext parsing for this Text.

set_path_effects(path_effects)

Set the path effects.

set_picker(picker)

Define the picking behavior of the artist.

set_position(xy)

Set the (x, y) position of the text.

set_rasterized(rasterized)

Force rasterized (bitmap) drawing for vector graphics output.

set_rotation(s)

Set the rotation of the text.

set_rotation_mode(m)

Set text rotation mode.

set_size(fontsize)

Alias for set_fontsize.

set_sketch_params([scale, length, randomness])

Set the sketch parameters.

set_snap(snap)

Set the snapping behavior.

set_stretch(stretch)

Alias for set_fontstretch.

set_style(fontstyle)

Alias for set_fontstyle.

set_text(s)

Set the text string s.

set_transform(t)

Set the artist transform.

set_transform_rotates_text(t)

Whether rotations of the transform affect the text direction.

set_url(url)

Set the url for the artist.

set_usetex(usetex)

Parameters usetex bool or None Whether to render using TeX, None means to use :rc:`text.usetex`. :4: (INFO/1) No role entry for "rc" in module "docutils.parsers.rst.languages.en". Trying "rc" as canonical role name. :4: (ERROR/3) Unknown interpreted text role "rc".

set_va(align)

Alias for set_verticalalignment.

set_variant(variant)

Alias for set_fontvariant.

set_verticalalignment(align)

Set the vertical alignment relative to the anchor point.

set_visible(b)

Set the artist's visibility.

set_weight(weight)

Alias for set_fontweight.

set_wrap(wrap)

Set whether the text can be wrapped.

set_x(x)

Set the x position of the text.

set_y(y)

Set the y position of the text.

set_zorder(level)

Set the zorder for the artist.

update(kwargs)

Update this artist's properties from the dict props.

update_bbox_position_size(renderer)

Update the location and the size of the bbox.

update_from(other)

Copy properties from other to self.

update_positions(renderer)

Update the pixel positions of the annotation text and the arrow patch.

Attributes

anncoords

The coordinate system to use for .Annotation.xyann.

axes

The ~.axes.Axes instance the artist resides in, or None.

mouseover

Return whether this artist is queried for custom context information when the mouse cursor moves over it.

stale

Whether the artist is 'stale' and needs to be re-drawn for the output to match the internal state of the artist.

sticky_edges

x and y sticky edge lists for autoscaling.

xyann

The text position.

xycoords

zorder

add_callback(func)

Add a callback function that will be called whenever one of the .Artist’s properties changes.

Parameters

funccallable

The callback function. It must have the signature:

def func(artist: Artist) -> Any

where artist is the calling .Artist. Return values may exist but are ignored.

Returns

int

The observer id associated with the callback. This id can be used for removing the callback with .remove_callback later.

See Also

remove_callback

property anncoords

The coordinate system to use for .Annotation.xyann.

property axes

The ~.axes.Axes instance the artist resides in, or None.

contains(event)[source]

Return whether the mouse event occurred inside the axis-aligned bounding-box of the text.

convert_xunits(x)

Convert x using the unit type of the xaxis.

If the artist is not contained in an Axes or if the xaxis does not have units, x itself is returned.

convert_yunits(y)

Convert y using the unit type of the yaxis.

If the artist is not contained in an Axes or if the yaxis does not have units, y itself is returned.

draggable(state=None, use_blit=False)

Set whether the annotation is draggable with the mouse.

Parameters

statebool or None
  • True or False: set the draggability.

  • None: toggle the draggability.

Returns

DraggableAnnotation or None

If the annotation is draggable, the corresponding .DraggableAnnotation helper is returned.

draw(renderer)[source]

Draw the Artist (and its children) using the given renderer.

This has no effect if the artist is not visible (.Artist.get_visible returns False).

Parameters

renderer : .RendererBase subclass.

Notes

This method is overridden in the Artist subclasses.

findobj(match=None, include_self=True)

Find artist objects.

Recursively find all .Artist instances contained in the artist.

Parameters

match

A filter criterion for the matches. This can be

  • None: Return all objects contained in artist.

  • A function with signature def match(artist: Artist) -> bool. The result will only contain artists for which the function returns True.

  • A class instance: e.g., .Line2D. The result will only contain artists of this class or its subclasses (isinstance check).

include_selfbool

Include self in the list to be checked for a match.

Returns

list of .Artist

format_cursor_data(data)

Return a string representation of data.

Note

This method is intended to be overridden by artist subclasses. As an end-user of Matplotlib you will most likely not call this method yourself.

The default implementation converts ints and floats and arrays of ints and floats into a comma-separated string enclosed in square brackets, unless the artist has an associated colorbar, in which case scalar values are formatted using the colorbar’s formatter.

See Also

get_cursor_data

get_agg_filter()

Return filter function to be used for agg filter.

get_alpha()

Return the alpha value used for blending - not supported on all backends.

get_animated()

Return whether the artist is animated.

get_anncoords()[source]

Return the coordinate system to use for .Annotation.xyann.

See also xycoords in .Annotation.

get_annotation_clip()

Return the annotation’s clipping behavior.

See set_annotation_clip for the meaning of return values.

get_bbox_patch()

Return the bbox Patch, or None if the .patches.FancyBboxPatch is not made.

get_c()

Alias for get_color.

get_children()

Return a list of the child .Artists of this .Artist.

get_clip_box()

Return the clipbox.

get_clip_on()

Return whether the artist uses clipping.

get_clip_path()

Return the clip path.

get_color()

Return the color of the text.

get_cursor_data(event)

Return the cursor data for a given event.

Note

This method is intended to be overridden by artist subclasses. As an end-user of Matplotlib you will most likely not call this method yourself.

Cursor data can be used by Artists to provide additional context information for a given event. The default implementation just returns None.

Subclasses can override the method and return arbitrary data. However, when doing so, they must ensure that .format_cursor_data can convert the data to a string representation.

The only current use case is displaying the z-value of an .AxesImage in the status bar of a plot window, while moving the mouse.

Parameters

event : matplotlib.backend_bases.MouseEvent

See Also

format_cursor_data

get_family()

Alias for get_fontfamily.

get_figure()

Return the .Figure instance the artist belongs to.

get_font()

Alias for get_fontproperties.

get_font_properties()

Alias for get_fontproperties.

get_fontfamily()

Return the list of font families used for font lookup.

See Also

.font_manager.FontProperties.get_family

get_fontname()

Return the font name as a string.

See Also

.font_manager.FontProperties.get_name

get_fontproperties()

Return the .font_manager.FontProperties.

get_fontsize()

Return the font size as an integer.

See Also

.font_manager.FontProperties.get_size_in_points

get_fontstyle()

Return the font style as a string.

See Also

.font_manager.FontProperties.get_style

get_fontvariant()

Return the font variant as a string.

See Also

.font_manager.FontProperties.get_variant

get_fontweight()

Return the font weight as a string or a number.

See Also

.font_manager.FontProperties.get_weight

get_gid()

Return the group id.

get_ha()

Alias for get_horizontalalignment.

get_horizontalalignment()

Return the horizontal alignment as a string. Will be one of ‘left’, ‘center’ or ‘right’.

get_in_layout()

Return boolean flag, True if artist is included in layout calculations.

E.g. /tutorials/intermediate/constrainedlayout_guide, .Figure.tight_layout(), and fig.savefig(fname, bbox_inches='tight').

get_label()

Return the label used for this artist in the legend.

get_math_fontfamily()

Return the font family name for math text rendered by Matplotlib.

The default value is :rc:`mathtext.fontset`.

See Also

set_math_fontfamily

get_mouseover()

Return whether this artist is queried for custom context information when the mouse cursor moves over it.

get_name()

Alias for get_fontname.

get_parse_math()

Return whether mathtext parsing is considered for this Text.

get_picker()

Return the picking behavior of the artist.

The possible values are described in .set_picker.

See Also

set_picker, pickable, pick

get_position()

Return the (x, y) position of the text.

get_prop_tup(renderer=None)

[Deprecated] 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.

Notes

Deprecated since version 3.5.

get_rasterized()

Return whether the artist is to be rasterized.

get_rotation()

Return the text angle in degrees between 0 and 360.

get_rotation_mode()

Return the text rotation mode.

get_size()

Alias for get_fontsize.

get_sketch_params()

Return the sketch parameters for the artist.

Returns

tuple or None

A 3-tuple with the following elements:

  • scale: The amplitude of the wiggle perpendicular to the source line.

  • length: The length of the wiggle along the line.

  • randomness: The scale factor by which the length is shrunken or expanded.

Returns None if no sketch parameters were set.

get_snap()

Return the snap setting.

See .set_snap for details.

get_stretch()

Return the font stretch as a string or a number.

See Also

.font_manager.FontProperties.get_stretch

get_style()

Alias for get_fontstyle.

get_text()

Return the text string.

get_tightbbox(renderer=None)[source]

Like .Artist.get_window_extent, but includes any clipping.

Parameters

renderer.RendererBase subclass

renderer that will be used to draw the figures (i.e. fig.canvas.get_renderer())

Returns

.Bbox

The enclosing bounding box (in figure pixel coordinates).

get_transform()

Return the .Transform instance used by this artist.

get_transform_rotates_text()

Return whether rotations of the transform affect the text direction.

get_transformed_clip_path_and_affine()

Return the clip path with the non-affine part of its transformation applied, and the remaining affine part of its transformation.

get_unitless_position()

Return the (x, y) unitless position of the text.

get_url()

Return the url.

get_usetex()

Return whether this Text object uses TeX for rendering.

get_va()

Alias for get_verticalalignment.

get_variant()

Alias for get_fontvariant.

get_verticalalignment()

Return the vertical alignment as a string. Will be one of ‘top’, ‘center’, ‘bottom’, ‘baseline’ or ‘center_baseline’.

get_visible()

Return the visibility.

get_weight()

Alias for get_fontweight.

get_window_extent(renderer=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

rendererRenderer, optional

A renderer is needed to compute the bounding box. If the artist has already been drawn, the renderer is cached; thus, it is only necessary to pass this argument when calling get_window_extent before the first draw. In practice, it is usually easier to trigger a draw first, e.g. by calling ~.Figure.draw_without_rendering or plt.show().

dpifloat, optional

The dpi value for computing the bbox, defaults to self.figure.dpi (not the renderer dpi); should be set e.g. if to match regions with a figure saved with a custom dpi value.

get_wrap()

Return whether the text can be wrapped.

get_zorder()

Return the artist’s zorder.

have_units()

Return whether units are set on any axis.

is_transform_set()

Return whether the Artist has an explicitly set transform.

This is True after .set_transform has been called.

property mouseover

Return whether this artist is queried for custom context information when the mouse cursor moves over it.

pchanged()

Call all of the registered callbacks.

This function is triggered internally when a property is changed.

See Also

add_callback remove_callback

pick(mouseevent)

Process a pick event.

Each child artist will fire a pick event if mouseevent is over the artist and the artist has picker set.

See Also

set_picker, get_picker, pickable

pickable()

Return whether the artist is pickable.

See Also

set_picker, get_picker, pick

properties()

Return a dictionary of all the properties of the artist.

remove()

Remove the artist from the figure if possible.

The effect will not be visible until the figure is redrawn, e.g., with .FigureCanvasBase.draw_idle. Call ~.axes.Axes.relim to update the axes limits if desired.

Note: ~.axes.Axes.relim will not see collections even if the collection was added to the axes with autolim = True.

Note: there is no support for removing the artist’s legend entry.

remove_callback(oid)

Remove a callback based on its observer id.

See Also

add_callback

set(*, agg_filter=<UNSET>, alpha=<UNSET>, animated=<UNSET>, anncoords=<UNSET>, annotation_clip=<UNSET>, backgroundcolor=<UNSET>, bbox=<UNSET>, clip_box=<UNSET>, clip_on=<UNSET>, clip_path=<UNSET>, color=<UNSET>, fontfamily=<UNSET>, fontproperties=<UNSET>, fontsize=<UNSET>, fontstretch=<UNSET>, fontstyle=<UNSET>, fontvariant=<UNSET>, fontweight=<UNSET>, gid=<UNSET>, horizontalalignment=<UNSET>, in_layout=<UNSET>, label=<UNSET>, linespacing=<UNSET>, math_fontfamily=<UNSET>, mouseover=<UNSET>, multialignment=<UNSET>, parse_math=<UNSET>, path_effects=<UNSET>, picker=<UNSET>, position=<UNSET>, rasterized=<UNSET>, rotation=<UNSET>, rotation_mode=<UNSET>, sketch_params=<UNSET>, snap=<UNSET>, text=<UNSET>, transform=<UNSET>, transform_rotates_text=<UNSET>, url=<UNSET>, usetex=<UNSET>, verticalalignment=<UNSET>, visible=<UNSET>, wrap=<UNSET>, x=<UNSET>, y=<UNSET>, zorder=<UNSET>)

Set multiple properties at once.

Supported properties are

Properties:

agg_filter: a filter function, which takes a (m, n, 3) float array and a dpi value, and returns a (m, n, 3) array and two offsets from the bottom left corner of the image alpha: scalar or None animated: bool anncoords: unknown annotation_clip: bool or None backgroundcolor: color bbox: dict with properties for .patches.FancyBboxPatch clip_box: .Bbox clip_on: bool clip_path: Patch or (Path, Transform) or None color or c: color figure: unknown fontfamily or family: {FONTNAME, ‘serif’, ‘sans-serif’, ‘cursive’, ‘fantasy’, ‘monospace’} fontproperties or font or font_properties: .font_manager.FontProperties or str or pathlib.Path fontsize or size: float or {‘xx-small’, ‘x-small’, ‘small’, ‘medium’, ‘large’, ‘x-large’, ‘xx-large’} fontstretch or stretch: {a numeric value in range 0-1000, ‘ultra-condensed’, ‘extra-condensed’, ‘condensed’, ‘semi-condensed’, ‘normal’, ‘semi-expanded’, ‘expanded’, ‘extra-expanded’, ‘ultra-expanded’} fontstyle or style: {‘normal’, ‘italic’, ‘oblique’} fontvariant or variant: {‘normal’, ‘small-caps’} fontweight or weight: {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 or ha: {‘left’, ‘center’, ‘right’} in_layout: bool label: object linespacing: float (multiple of font size) math_fontfamily: str mouseover: bool multialignment or ma: {‘left’, ‘right’, ‘center’} parse_math: bool path_effects: .AbstractPathEffect picker: None or bool or float or callable position: (float, float) rasterized: bool rotation: float or {‘vertical’, ‘horizontal’} rotation_mode: {None, ‘default’, ‘anchor’} sketch_params: (scale: float, length: float, randomness: float) snap: bool or None text: object transform: .Transform transform_rotates_text: bool url: str usetex: bool or None verticalalignment or va: {‘bottom’, ‘baseline’, ‘center’, ‘center_baseline’, ‘top’} visible: bool wrap: bool x: float y: float zorder: float

set_agg_filter(filter_func)

Set the agg filter.

Parameters

filter_funccallable

A filter function, which takes a (m, n, depth) float array and a dpi value, and returns a (m, n, depth) array and two offsets from the bottom left corner of the image

set_alpha(alpha)

Set the alpha value used for blending - not supported on all backends.

Parameters

alphascalar or None

alpha must be within the 0-1 range, inclusive.

set_animated(b)

Set whether the artist is intended to be used in an animation.

If True, the artist is excluded from regular drawing of the figure. You have to call .Figure.draw_artist / .Axes.draw_artist explicitly on the artist. This approach is used to speed up animations using blitting.

See also matplotlib.animation and /tutorials/advanced/blitting.

Parameters

b : bool

set_anncoords(coords)[source]

Set the coordinate system to use for .Annotation.xyann.

See also xycoords in .Annotation.

set_annotation_clip(b)

Set the annotation’s clipping behavior.

Parameters

bbool or None
  • True: The annotation will be clipped when self.xy is outside the axes.

  • False: The annotation will always be drawn.

  • None: The annotation will be clipped when self.xy is outside the axes and self.xycoords == "data".

set_backgroundcolor(color)

Set the background color of the text by updating the bbox.

Parameters

color : color

See Also

.set_bbox : To change the position of the bounding box

set_bbox(rectprops)

Draw a bounding box around self.

Parameters

rectpropsdict with properties for .patches.FancyBboxPatch

The default boxstyle is ‘square’. The mutation scale of the .patches.FancyBboxPatch is set to the fontsize.

Examples

t.set_bbox(dict(facecolor='red', alpha=0.5))
set_c(color)

Alias for set_color.

set_clip_box(clipbox)

Set the artist’s clip .Bbox.

Parameters

clipbox : .Bbox

set_clip_on(b)

Set whether the artist uses clipping.

When False artists will be visible outside of the Axes which can lead to unexpected results.

Parameters

b : bool

set_clip_path(path, transform=None)

Set the artist’s clip path.

Parameters

path.Patch or .Path or .TransformedPath or None

The clip path. If given a .Path, transform must be provided as well. If None, a previously set clip path is removed.

transform~matplotlib.transforms.Transform, optional

Only used if path is a .Path, in which case the given .Path is converted to a .TransformedPath using transform.

Notes

For efficiency, if path is a .Rectangle this method will set the clipping box to the corresponding rectangle and set the clipping path to None.

For technical reasons (support of ~.Artist.set), a tuple (path, transform) is also accepted as a single positional parameter.

set_color(color)

Set the foreground color of the text

Parameters

color : color

set_family(fontname)

Alias for set_fontfamily.

set_figure(fig)[source]

Set the .Figure instance the artist belongs to.

Parameters

fig : .Figure

set_font(fp)

Alias for set_fontproperties.

set_font_properties(fp)

Alias for set_fontproperties.

set_fontfamily(fontname)

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.

If a Text instance is constructed with fontfamily=None, then the font is set to :rc:`font.family`, and the same is done when set_fontfamily() is called on an existing Text instance.

Parameters

fontname : {FONTNAME, ‘serif’, ‘sans-serif’, ‘cursive’, ‘fantasy’, ‘monospace’}

See Also

.font_manager.FontProperties.set_family

set_fontname(fontname)

Alias for set_family.

One-way alias only: the getter differs.

Parameters

fontname : {FONTNAME, ‘serif’, ‘sans-serif’, ‘cursive’, ‘fantasy’, ‘monospace’}

See Also

.font_manager.FontProperties.set_family

set_fontproperties(fp)

Set the font properties that control the text.

Parameters

fp.font_manager.FontProperties or str or pathlib.Path

If a str, it is interpreted as a fontconfig pattern parsed by .FontProperties. If a pathlib.Path, it is interpreted as the absolute path to a font file.

set_fontsize(fontsize)

Set the font size.

Parameters

fontsizefloat or {‘xx-small’, ‘x-small’, ‘small’, ‘medium’, ‘large’, ‘x-large’, ‘xx-large’}

If float, the fontsize in points. The string values denote sizes relative to the default font size.

See Also

.font_manager.FontProperties.set_size

set_fontstretch(stretch)

Set the font stretch (horizontal condensation or expansion).

Parameters

stretch : {a numeric value in range 0-1000, ‘ultra-condensed’, ‘extra-condensed’, ‘condensed’, ‘semi-condensed’, ‘normal’, ‘semi-expanded’, ‘expanded’, ‘extra-expanded’, ‘ultra-expanded’}

See Also

.font_manager.FontProperties.set_stretch

set_fontstyle(fontstyle)

Set the font style.

Parameters

fontstyle : {‘normal’, ‘italic’, ‘oblique’}

See Also

.font_manager.FontProperties.set_style

set_fontvariant(variant)

Set the font variant.

Parameters

variant : {‘normal’, ‘small-caps’}

See Also

.font_manager.FontProperties.set_variant

set_fontweight(weight)

Set the font weight.

Parameters

weight : {a numeric value in range 0-1000, ‘ultralight’, ‘light’, ‘normal’, ‘regular’, ‘book’, ‘medium’, ‘roman’, ‘semibold’, ‘demibold’, ‘demi’, ‘bold’, ‘heavy’, ‘extra bold’, ‘black’}

See Also

.font_manager.FontProperties.set_weight

set_gid(gid)

Set the (group) id for the artist.

Parameters

gid : str

set_ha(align)

Alias for set_horizontalalignment.

set_horizontalalignment(align)

Set the horizontal alignment relative to the anchor point.

See also /gallery/text_labels_and_annotations/text_alignment.

Parameters

align : {‘left’, ‘center’, ‘right’}

set_in_layout(in_layout)

Set if artist is to be included in layout calculations, E.g. /tutorials/intermediate/constrainedlayout_guide, .Figure.tight_layout(), and fig.savefig(fname, bbox_inches='tight').

Parameters

in_layout : bool

set_label(s)

Set a label that will be displayed in the legend.

Parameters

sobject

s will be converted to a string by calling str.

set_linespacing(spacing)

Set the line spacing as a multiple of the font size.

The default line spacing is 1.2.

Parameters

spacing : float (multiple of font size)

set_ma(align)

Alias for set_multialignment.

set_math_fontfamily(fontfamily)

Set the font family for math text rendered by Matplotlib.

This does only affect Matplotlib’s own math renderer. It has no effect when rendering with TeX (usetex=True).

Parameters

fontfamilystr

The name of the font family.

Available font families are defined in the matplotlibrc.template file.

See Also

get_math_fontfamily

set_mouseover(mouseover)

Set whether this artist is queried for custom context information when the mouse cursor moves over it.

Parameters

mouseover : bool

See Also

get_cursor_data .ToolCursorPosition .NavigationToolbar2

set_multialignment(align)

Set the text alignment for multiline texts.

The layout of the bounding box of all the lines is determined by the horizontalalignment and verticalalignment properties. This property controls the alignment of the text lines within that box.

Parameters

align : {‘left’, ‘right’, ‘center’}

set_name(fontname)

Alias for set_fontname.

set_parse_math(parse_math)

Override switch to disable any mathtext parsing for this Text.

Parameters

parse_mathbool

If False, this Text will never use mathtext. If True, mathtext will be used if there is an even number of unescaped dollar signs.

set_path_effects(path_effects)

Set the path effects.

Parameters

path_effects : .AbstractPathEffect

set_picker(picker)

Define the picking behavior of the artist.

Parameters

pickerNone or bool or float or callable

This can be one of the following:

  • None: Picking is disabled for this artist (default).

  • A boolean: If True then picking will be enabled and the artist will fire a pick event if the mouse event is over the artist.

  • A float: If picker is a number it is interpreted as an epsilon tolerance in points and the artist will fire off an event if its data is within epsilon of the mouse event. For some artists like lines and patch collections, the artist may provide additional data to the pick event that is generated, e.g., the indices of the data within epsilon of the pick event

  • A function: If picker is callable, it is a user supplied function which determines whether the artist is hit by the mouse event:

    hit, props = picker(artist, mouseevent)
    

    to determine the hit test. if the mouse event is over the artist, return hit=True and props is a dictionary of properties you want added to the PickEvent attributes.

set_position(xy)

Set the (x, y) position of the text.

Parameters

xy : (float, float)

set_rasterized(rasterized)

Force rasterized (bitmap) drawing for vector graphics output.

Rasterized drawing is not supported by all artists. If you try to enable this on an artist that does not support it, the command has no effect and a warning will be issued.

This setting is ignored for pixel-based output.

See also /gallery/misc/rasterization_demo.

Parameters

rasterized : bool

set_rotation(s)

Set the rotation of the text.

Parameters

sfloat or {‘vertical’, ‘horizontal’}

The rotation angle in degrees in mathematically positive direction (counterclockwise). ‘horizontal’ equals 0, ‘vertical’ equals 90.

set_rotation_mode(m)

Set text rotation mode.

Parameters

m{None, ‘default’, ‘anchor’}

If None or "default", the text will be first rotated, then aligned according to their horizontal and vertical alignments. If "anchor", then alignment occurs before rotation.

set_size(fontsize)

Alias for set_fontsize.

set_sketch_params(scale=None, length=None, randomness=None)

Set the sketch parameters.

Parameters

scalefloat, optional

The amplitude of the wiggle perpendicular to the source line, in pixels. If scale is None, or not provided, no sketch filter will be provided.

lengthfloat, optional

The length of the wiggle along the line, in pixels (default 128.0)

randomnessfloat, optional

The scale factor by which the length is shrunken or expanded (default 16.0)

The PGF backend uses this argument as an RNG seed and not as described above. Using the same seed yields the same random shape.

set_snap(snap)

Set the snapping behavior.

Snapping aligns positions with the pixel grid, which results in clearer images. For example, if a black line of 1px width was defined at a position in between two pixels, the resulting image would contain the interpolated value of that line in the pixel grid, which would be a grey value on both adjacent pixel positions. In contrast, snapping will move the line to the nearest integer pixel value, so that the resulting image will really contain a 1px wide black line.

Snapping is currently only supported by the Agg and MacOSX backends.

Parameters

snapbool or None

Possible values:

  • True: Snap vertices to the nearest pixel center.

  • False: Do not modify vertex positions.

  • None: (auto) If the path contains only rectilinear line segments, round to the nearest pixel center.

set_stretch(stretch)

Alias for set_fontstretch.

set_style(fontstyle)

Alias for set_fontstyle.

set_text(s)

Set the text string s.

It may contain newlines (\n) or math in LaTeX syntax.

Parameters

sobject

Any object gets converted to its str representation, except for None which is converted to an empty string.

set_transform(t)

Set the artist transform.

Parameters

t : .Transform

set_transform_rotates_text(t)

Whether rotations of the transform affect the text direction.

Parameters

t : bool

set_url(url)

Set the url for the artist.

Parameters

url : str

set_usetex(usetex)

Parameters

usetexbool or None

Whether to render using TeX, None means to use :rc:`text.usetex`.

set_va(align)

Alias for set_verticalalignment.

set_variant(variant)

Alias for set_fontvariant.

set_verticalalignment(align)

Set the vertical alignment relative to the anchor point.

See also /gallery/text_labels_and_annotations/text_alignment.

Parameters

align : {‘bottom’, ‘baseline’, ‘center’, ‘center_baseline’, ‘top’}

set_visible(b)

Set the artist’s visibility.

Parameters

b : bool

set_weight(weight)

Alias for set_fontweight.

set_wrap(wrap)

Set whether the text can be wrapped.

Parameters

wrap : bool

Notes

Wrapping does not work together with savefig(..., bbox_inches='tight') (which is also used internally by %matplotlib inline in IPython/Jupyter). The ‘tight’ setting rescales the canvas to accommodate all content and happens before wrapping.

set_x(x)

Set the x position of the text.

Parameters

x : float

set_y(y)

Set the y position of the text.

Parameters

y : float

set_zorder(level)

Set the zorder for the artist. Artists with lower zorder values are drawn first.

Parameters

level : float

property stale

Whether the artist is ‘stale’ and needs to be re-drawn for the output to match the internal state of the artist.

property sticky_edges

x and y sticky edge lists for autoscaling.

When performing autoscaling, if a data limit coincides with a value in the corresponding sticky_edges list, then no margin will be added–the view limit “sticks” to the edge. A typical use case is histograms, where one usually expects no margin on the bottom edge (0) of the histogram.

Moreover, margin expansion “bumps” against sticky edges and cannot cross them. For example, if the upper data limit is 1.0, the upper view limit computed by simple margin application is 1.2, but there is a sticky edge at 1.1, then the actual upper view limit will be 1.1.

This attribute cannot be assigned to; however, the x and y lists can be modified in place as needed.

Examples

>>> artist.sticky_edges.x[:] = (xmin, xmax)
>>> artist.sticky_edges.y[:] = (ymin, ymax)
update(kwargs)

Update this artist’s properties from the dict props.

Parameters

props : dict

update_bbox_position_size(renderer)

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.

update_from(other)

Copy properties from other to self.

update_positions(renderer)[source]

Update the pixel positions of the annotation text and the arrow patch.

property xyann

The text position.

See also xytext in .Annotation.