Documentation Center

  • Trials
  • Product Updates

annotation

Create annotation objects

Syntax

annotation(annotation_type)
annotation('line',x,y)
annotation('arrow',x,y)
annotation('doublearrow',x,y)
annotation('textarrow',x,y)
annotation('textbox',[x y w h])
annotation('ellipse',[x y w h])
annotation('rectangle',[x y w h])
annotation(figure_handle,...)
annotation(...,'PropertyName',PropertyValue,...)
anno_obj_handle = annotation(...)

Description

annotation(annotation_type) creates the specified annotation type using default values for all properties. annotation_type can be one of the following strings:

  • 'line'

  • 'arrow'

  • 'doublearrow' (two-headed arrow),

  • 'textarrow' (arrow with attached text box),

  • 'textbox'

  • 'ellipse'

  • 'rectangle'

annotation('line',x,y) creates a line annotation object that extends from the point defined by x(1),y(1) to the point defined by x(2),y(2), specified in normalized figure units.

annotation('arrow',x,y) creates an arrow annotation object that extends from the point defined by x(1),y(1) to the point defined by x(2),y(2), specified in normalized figure units.

annotation('doublearrow',x,y) creates a two-headed annotation object that extends from the point defined by x(1),y(1) to the point defined by x(2),y(2), specified in normalized figure units.

annotation('textarrow',x,y) creates a textarrow annotation object that extends from the point defined by x(1),y(1) to the point defined by x(2),y(2), specified in normalized figure units. The tail end of the arrow is attached to an editable text box.

annotation('textbox',[x y w h]) creates an editable text box annotation with its lower left corner at the point x,y, a width w, and a height h, specified in normalized figure units. Specify x, y, w, and h in a single vector.

To type in the text box, enable plot edit mode (plotedit) and double-click within the box.

annotation('ellipse',[x y w h]) creates an ellipse annotation with the lower left corner of the bounding rectangle at the point x,y, a width w, and a height h, specified in normalized figure units. Specify x, y, w, and h in a single vector.

annotation('rectangle',[x y w h]) creates a rectangle annotation with the lower left corner of the rectangle at the point x,y, a width w, and a height h, specified in normalized figure units. Specify x, y, w, and h in a single vector.

annotation(figure_handle,...) creates the annotation in the specified figure.

annotation(...,'PropertyName',PropertyValue,...) creates the annotation and sets the specified properties to the specified values.

anno_obj_handle = annotation(...) returns the handle to the Annotation Objects.

Examples

expand all

Add Text Box to Graph

Annotate the graph with a text box. Specify the text box location in normalized figure coordinates.

figure; % new figure window
plot(1:10);
annotation('textbox', [0.2,0.4,0.1,0.1],...
           'String', 'Straight Line Plot 1 to 10');

Add Text Box with Multiple Lines to Graph

Insert multiple lines in a text box by creating a cell array of strings. Each element is used as a separate line.

figure
plot(1:10);
str = {'Straight Line', 'Plot of 1 to 10'};
annotation('textbox', [0.2,0.4,0.1,0.1],...
           'String', str);

Add Text Arrow to Graph

Add a text arrow to the graph. Define the text arrow to start from (0.3,0.6) and extend to (0.5,0.5) in normalized figure coordinates.

figure
plot(1:10);
annotation('textarrow', [0.3,0.5], [0.6,0.5],...
           'String' , 'Straight Line');

Adding Annotations Interactively

It is often convenient to place annotations interactively. For details, see Customize Graph Using Plot Tools.

See Also

| | | | | |

Was this topic helpful?