annotation
Create figure annotations.
📝Syntax
annotation(lineType, x, y)
annotation(lineType)
annotation(shapeType, dim)
annotation(shapeType)
annotation(..., propertyName, propertyValue)
annotation(fig, ...)
go = annotation(...)
📥Input Arguments
Parameter Description
lineType 'line', 'arrow', 'doublearrow', or 'textarrow'.
shapeType 'rectangle', 'ellipse', or 'textbox'.
x, y Two-element vectors defining beginning and ending coordinates.
dim Four-element vector [x y w h].
fig Target figure.
📤Output Arguments
Parameter Description
go Annotation graphics object.
📄Description

annotation creates annotations in figure coordinates. Default units are normalized.

Supported units are 'normalized', 'inches', 'centimeters', 'characters', 'points', and 'pixels'.

See annotation properties for the complete property list.

💡Examples
Add a line annotation.
f = figure();
plot(1:10);
annotation('line', [0.15 0.85], [0.75 0.75], ...
  'Color', [0 0.45 0.74], 'LineWidth', 2);
Example illustration
Add an arrow annotation.
f = figure();
plot(1:10);
annotation('arrow', [0.25 0.55], [0.65 0.45], ...
  'Color', 'red', 'LineStyle', '--', 'HeadStyle', 'plain');
Example illustration
Add a double arrow annotation.
f = figure();
plot(1:10);
annotation('doublearrow', [0.25 0.75], [0.25 0.25], ...
  'Head1Style', 'vback1', 'Head2Style', 'cback3', 'LineWidth', 1.5);
Example illustration
Add a text arrow annotation.
f = figure();
plot(1:10);
annotation('textarrow', [0.3 0.55], [0.7 0.55], ...
  'String', 'y = x', 'TextBackgroundColor', 'white');
Example illustration
Add a rectangle annotation.
f = figure();
plot(1:10);
annotation('rectangle', [0.3 0.4 0.25 0.2], ...
  'Color', 'red', 'FaceColor', 'yellow', 'FaceAlpha', 0.35, 'Rotation', 20);
Example illustration
Add an ellipse annotation.
f = figure();
plot(1:10);
annotation('ellipse', [0.55 0.35 0.25 0.2], ...
  'Color', [0.49 0.18 0.56], 'FaceColor', 'none', 'LineWidth', 1.5);
Example illustration
Add a text box annotation.
f = figure();
plot(1:10);
annotation('textbox', [0.18 0.78 0.28 0.1], ...
  'String', 'Important region', 'FitBoxToText', 'on', ...
  'BackgroundColor', 'white', 'EdgeColor', 'black');
Example illustration
🔗See Also
annotation properties
Edit this page on GitHub