matplotlib.axes.Axes.annotate — Matplotlib 3.10.1 documentation (original) (raw)

Axes.annotate(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.

xycoordssingle or two-tuple of str or Artist or Transform or callable, default: 'data'

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

See Advanced annotation for more details.

textcoordssingle or two-tuple of str or Artist or Transform or callable, default: value of xycoords

The coordinate system that xytext is given in.

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

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:

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 FancyArrowPatch parameters:

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), so 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.

**kwargs

Additional kwargs are passed to Text.

Returns:

Annotation

Examples using matplotlib.axes.Axes.annotate#