Quantcast

Documentation Center

  • Trial Software
  • Product Updates

text

Create text object in current axes

Syntax

text(x,y,'string')
text(x,y,z,'string')
text(x,y,z,'string','PropertyName',PropertyValue....)
text('PropertyName',PropertyValue....)
h = text(...)

Properties

For a list of properties, see Text Properties.

Description

text is the low-level function for creating text graphics objects. Use text to place character strings at specified locations.

text(x,y,'string') adds the string in quotes to the location specified by the point (x,y) x and y must be numbers of class double.

text(x,y,z,'string') adds the string in 3-D coordinates. x, y and z must be numbers of class double.

text(x,y,z,'string','PropertyName',PropertyValue....) adds the string in quotes to the location defined by the coordinates and uses the values for the specified text properties. For a description of the properties, see Text Properties.

text('PropertyName',PropertyValue....) omits the coordinates entirely and specifies all properties using property name/property value pairs.

h = text(...) returns a column vector of handles to text objects, one handle per object. All forms of the text function optionally return this output argument.

See the String property for a list of symbols, including Greek letters.

Examples

expand all

Label Point on Graph

Annotate the point $(\pi,0)$ with the string $\sin(\pi)$ .

x = 0:pi/20:2*pi;
y = sin(x);

figure % new figure window
plot(x,y);
text(pi,0,' \leftarrow sin(\pi)')

Display Equation with Greek Symbols

Use embedded TeX sequences to display an equation in an empty axes.

axes
text(0.5,0.5,'\ite^{i\omega\tau} = cos(\omega\tau) + i sin(\omega\tau)')

Setting Default Properties

You can set default text properties on the axes, figure, and rootobject levels:

set(0,'DefaulttextProperty',PropertyValue...)
set(gcf,'DefaulttextProperty',PropertyValue...)
set(gca,'DefaulttextProperty',PropertyValue...)

Where Property is the name of the text property and PropertyValue is the value you are specifying. Use set and get to access text properties.

More About

expand all

Tips

Position Text Within the Axes

The default text units are the units used to plot data in the graph. Specify the text location coordinates (the x, y, and z arguments) in the data units of the current graph (see Examples. You can use other units to position the text by setting the text Units property to normalized or one of the nonrelative units (pixels, inches, centimeters, points, or characters).

Note that the Axes Units property controls the positioning of the Axes within the figure and is not related to the axes data units used for graphing.

The Extent, VerticalAlignment, and HorizontalAlignment properties control the positioning of the character string with regard to the text location point.

If the coordinates are vectors, text writes the string at all locations defined by the list of points. If the character string is an array the same length as x, y, and z, text writes the corresponding row of the string array at each point specified.

Multiline Text

When specifying strings for multiple text objects, the string can be:

  • A cell array of strings

  • A padded string matrix

Each element of the specified string array creates a different text object.

When specifying the string for a single text object, cell arrays of strings and padded string matrices result in a text object with a multiline string, while vertical slash characters are not interpreted as separators and result in a single line string containing vertical slashes.

Behavior of the Text Function

text is a low-level function that accepts property name/property value pairs as input arguments. However, the convenience form:

text(x,y,z,'string')

is equivalent to:

text('Position',[x,y,z],'String','string')

You can specify other properties only as property name/property value pairs. For a description of each property, see Text Properties. You can specify properties as property name/property value pairs, structure arrays, and cell arrays (see the set and get reference pages for examples of how to specify these data types).

text does not respect the setting of the figure or axes NextPlot property. This allows you to add text objects to an existing axes without setting hold to on.

See Also

| | | | | | | | |

Was this topic helpful?