matplotlib.pyplot.annotate#
- matplotlib.pyplot.annotate(text,xy,xytext=None,xycoords='data',textcoords=None,arrowprops=None,annotation_clip=None,**kwargs)[source]#
Annotate the pointxy with texttext.
In the simplest form, the text is placed atxy.
Optionally, the text can be displayed in another positionxytext.An arrow pointing from the text to the annotated pointxy can thenbe added by definingarrowprops.
- Parameters:
- textstr
The text of the annotation.
- xy(float, float)
The point(x, y) to annotate. The coordinate system is determinedbyxycoords.
- xytext(float, float), default:xy
The position(x, y) to place the text at. The coordinate systemis determined bytextcoords.
- xycoordssingle or two-tuple of str or
Artist
orTransform
or callable, default: 'data' The coordinate system thatxy is given in. The following typesof 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 the Axes
'axes pixels'
Pixels from lower left corner of the Axes
'axes fraction'
Fraction of Axes from lower left
'data'
Use the coordinate system of the objectbeing annotated (default)
'polar'
(theta, r) if not native 'data'coordinates
Note that 'subfigure pixels' and 'figure pixels' are the samefor the parent figure, so users who want code that is usable ina subfigure can use 'subfigure pixels'.
An
Artist
:xy is interpreted as a fraction of the artist'sBbox
. E.g.(0, 0) would be the lowerleft corner of the bounding box and(0.5, 1) would be thecenter top of the bounding box.A
Transform
to transformxy to screen coordinates.A function with one of the following signatures:
deftransform(renderer)->Bboxdeftransform(renderer)->Transform
whererenderer is a
RendererBase
subclass.The result of the function is interpreted like the
Artist
andTransform
cases above.A tuple(xcoords, ycoords) specifying separate coordinatesystems forx andy.xcoords andycoords must each beof one of the above described types.
SeeAdvanced annotation for more details.
- textcoordssingle or two-tuple of str or
Artist
orTransform
or callable, default: value ofxycoords The coordinate system thatxytext is given in.
Allxycoords values are valid as well as the following strings:
Value
Description
'offset points'
Offset, in points, from thexy value
'offset pixels'
Offset, in pixels, from thexy value
'offset fontsize'
Offset, relative to fontsize, from thexy value
- arrowpropsdict, optional
The properties used to draw a
FancyArrowPatch
arrow between thepositionsxy andxytext. Defaults to None, i.e. no arrow isdrawn.For historical reasons there are two different ways to specifyarrows, "simple" and "fancy":
Simple arrow:
Ifarrowprops does not contain the key 'arrowstyle' theallowed 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
FancyArrowPatch
propertyThe arrow is attached to the edge of the text box, the exactposition (corners or centers) depending on where it's pointing to.
Fancy arrow:
This is used if 'arrowstyle' is provided in thearrowprops.
Valid keys are the following
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
In points. Default is 2 points
shrinkB
In points. Default is 2 points
mutation_scale
Default is text size (in points)
mutation_aspect
Default is 1
?
Any
FancyArrowPatch
propertyThe exact starting point position of the arrow is defined byrelpos. It's a tuple of relative coordinates of the text box,where (0, 0) is the lower left corner and (1, 1) is the upperright corner. Values <0 and >1 are supported and specify pointsoutside the text box. By default (0.5, 0.5), so the starting pointis centered in the text box.
- annotation_clipbool or None, default: None
Whether to clip (i.e. not draw) the annotation when the annotationpointxy is outside the Axes area.
IfTrue, the annotation will be clipped whenxy is outsidethe Axes.
IfFalse, the annotation will always be drawn.
IfNone, the annotation will be clipped whenxy is outsidethe Axes andxycoords is 'data'.
- **kwargs
Additional kwargs are passed to
Text
.
- Returns:
See also
Notes
Note
This is thepyplot wrapper for
axes.Axes.annotate
.