Graphics Previous page   Next Page

Creating Text Annotations with the text or gtext Command

To create a text annotation using the text function, you must specify the text and its location in the graph, using x- and y-coordinates. You specify the coordinates in the units of the graph.

Use the gtext command when you want to position a text annotation at a specific point in the data space with the mouse.

For example, the following code creates text annotations at specific points in the Lotka-Volterra Predator-Prey Population Model graph.

This example also illustrates how to create multiline text annotations with cell arrays.

Calculating the Positions of Text Annotations

You can also calculate the positions of text annotations in a graph. The following code adds annotations at three data points on a graph.

The HorizontalAlignment of the text string 'sin(t) = -.707 \rightarrow' is set to right to place it on the left side of the point [5*pi/4,sin(5*pi/4)] on the graph. For more information about aligning text annotations, see Text Alignment.

Defining Symbols.   For information on using symbols in text strings, see Mathematical Symbols, Greek Letters, and TEX Characters.

You can use text objects to annotate axes at arbitrary locations. MATLAB locates text in the data units of the axes. For example, suppose you plot the function with A = 0.25, alpha = 0.005, and t = 0 to 900.

To annotate the point where the value of t = 300, calculate the text coordinates using the function you are plotting.

This statement defines the text Position property as

x = 300,

The default text alignment places this point to the left of the string and centered vertically with the rectangle defined by the text Extent property. The following section provides more information about changing the default text alignment.


Previous page  Adding Text Annotations to Graphs Text Alignment Next page

© 1994-2005 The MathWorks, Inc.