annotation

Adds shapes and text, such as arrows and text boxes, to a figure.

Category: Graphics > Formatting and Annotation

Syntax

annotation(type)

Creates an annotation of the given type with default position.

annotation(type, position)

Places it at [x y w h] or, for lines and arrows, at x and y endpoints.

annotation(___, Name, Value)

Sets properties such as 'String'.

Description

Annotations belong to the figure, not to the axes, so they stay put when the data limits change. Positions are in the figure's normalized coordinates rather than in data units.

Input arguments

type
'line', 'arrow', 'doublearrow', 'textarrow', 'textbox', 'rectangle' or 'ellipse'.
position
Normalized figure units, from 0 to 1, measured from the lower-left corner of the figure.

Output arguments

h
Handle of the annotation object.

Example

A text box and an arrow

plot(1:5)
annotation('textbox', [0.3 0.6 0.2 0.1], 'String', 'Note');
annotation('arrow', [0.3 0.5], [0.3 0.5]);

In the app, the figure is drawn below the code.

See also

text title legend xline