MATLAB Functions Help Desk

text

Purpose

Create Text object in current Axes

Syntax

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).

text(x,y,z,'string') adds the string in 3-D coordinates.

text(x,y,z,'string','PropertyName',PropertyValue....) adds the string in quotes to location defined by the coordinates and uses the values for the specified 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.

Remarks

Specify the Text location coordinates (the x, y, and z arguments) in the data units of the current Axes (see "Examples"). 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.

When specifying strings for multiple Text objects, string can be a cell array of strings, a padded string matrix, or a string vector using vertical slash characters (`|') as separators, and each Text object will be assigned a different element of the specified string. 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.

While text is a low-level function that accepts property name/property value pairs as input arguments, the convince form,

is equivalent to:

You can specify other properties only as property name/property value pairs. See the "Text Properties" section for a description of each property. 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.

Examples

The statements,

annotate the point at (pi,0) with the string ¨sin():

The statement,

uses imbedded LaTeX sequences to produce:

Object Hierarchy



Setting Default Properties

You can set default Text properties on the Axes, Figure, and Root levels:

Where Property is the name of the Text property and PropertyValue is the value you are specifying.

Text Properties

This section lists property names along with the type of values each accepts. Curly braces { } enclose default values.

BusyAction             cancel | {queue}

Callback routine interruption. The BusyAction property enables you to control how MATLAB handles events that potentially interrupt executing callback routines. If there is a callback routine executing, subsequently invoked callback routes always attempt to interrupt it. If the Interruptible property of the object whose callback is executing is set to on (the default), then interruption occurs at the next point where the event queue is processed. If the Interruptible property is off, the BusyAction property (of the object owning the executing callback) determines how MATLAB handles the event. The choices are:

ButtonDownFcn          string

Button press callback routine. A callback routine that executes whenever you press a mouse button while the pointer is over the Text object. Define this routine as a string that is a valid MATLAB expression or the name of an M-file. The expression executes in the MATLAB workspace.

Children               matrix (read only)

The empty matrix; Text objects have no children.

Clipping               on | {off}

Clipping mode. When Clipping is on, MATLAB does not display any portion of the Text that is outside the Axes.

Color                  ColorSpec

Text color. A three-element RGB vector or one of MATLAB's predefined names, specifying the Text color. The default value for Color is white. See the ColorSpec reference page for more information on specifying color.

CreateFcn              string

Callback routine executed during object creation. This property defines a callback routine that executes when MATLAB creates a Text object. You must define this property as a default value for Text. For example, the statement,

defines a default value on the Root level that sets the Figure Pointer property to a crosshair whenever you create a Text object. MATLAB executes this routine after setting all Text properties. Setting this property on an existing Text object has no effect.

The handle of the object whose CreateFcn is being executed is accessible only through the Root CallbackObject property, which can be queried using gcbo.

DeleteFcn              string

Delete Text callback routine. A callback routine that executes when you delete the Text object (e.g., when you issue a delete command or clear the Axes or Figure). MATLAB executes the routine before destroying the object's properties so these values are available to the callback routine.

The handle of the object whose DeleteFcn is being executed is accessible only through the Root CallbackObject property, which can be queried using gcbo.

EraseMode              {normal} | none | xor | background

Erase mode. This property controls the technique MATLAB uses to draw and erase Text objects. Alternative erase modes are useful for creating animated sequences, where control of the way individual object redraw is necessary to improve performance and obtain the desired effect.

Extent                 position rectangle (read only)

Position and size of Text. A four-element read-only vector that defines the size and position of the Text string:

left and bottom are the distance from the lower-left corner of the Axes rectangle to the lower-left corner of the Text Extent rectangle. width and height are the dimensions of the Extent rectangle. All measurements are in units specified by the Units property.

FontAngle              {normal} | italic | oblique

Character slant. MATLAB uses this property to select a font from those available on your particular system. Generally, setting this property to italic or oblique selects a slanted font.

FontName               string

Font family. A string specifying the name of the font to use for the Text object. To display and print properly, this must be a font that your system supports. The default font is Helvetica.

FontSize               size in FontUnits

Font size. An integer specifying the font size to use for Text, in units determined by the FontUnits property. The default point size is 10 (1 point = 1/72 inch).

FontWeight             light | {normal} | demi | bold

Weight of Text characters. MATLAB uses this property to select a font from those available on your particular system. Generally, setting this property to bold or demi causes MATLAB to use a bold font.

FontUnits              {points} | normalized | inches | centimeters |
 pixels

Font size units. MATLAB uses this property to determine the units used by the FontSize property. Normalized units interpret FontSize as a fraction of the height of the parent Axes. When you resize the Axes, MATLAB modifies the screen FontSize accordingly. pixels, inches, centimeters, and points are absolute units (1 point = 1/72 inch).

HandleVisibility       {on} | callback | off

Control access to object's handle by command-line users and GUIs. This property determines when an object's handle is visible in its parent's list of children. Handles are always visible when HandleVisibility is on. When HandleVisibility is callback, handles are visible from within callbacks or functions invoked by callbacks, but not from within functions invoked from the command line - a useful way to protect GUIs from command-line users, while permitting their callbacks complete access to their own handles. Setting HandleVisibility to off makes handles invisible at all times - which is occasionally necessary when a callback needs to invoke a function that might potentially damage the UI, and so wants to temporarily hide its own handles during the execution of that function.

When a handle is not visible in its parent's list of children, it can not be returned by any functions which obtain handles by searching the object hierarchy or querying handle properties, including get, findobj, gca, gcf, gco, newplot, cla, clf, and close. When a handle's visibility is restricted using callback or off, the object's handle does not appear in its parent's Children property, Figures do not appear in the Root's CurrentFigure property, objects do not appear in the Root's CallbackObject property or in the Figure's CurrentObject property, and Axes do not appear in their parent's CurrentAxes property.

The Root ShowHiddenHandles property can be set to on to temporarily make all handles visible, regardless of their HandleVisibility settings (this does not affect the values of the HandleVisibility properties).

Handles that are hidden are still valid. If you know an object's handle, you can set and get its properties, and pass it to any function that operates on handles. This property is useful for preventing command-line users from accidently drawing into or deleting a Figure that contains only user interface devices (such as a dialog box).

HorizontalAlignment    {left} | center | right

Horizontal alignment of Text. This property specifies the horizontal justification of the Text string. It determines where MATLAB places the string with regard to the point specified by the Position property.

Interpreter            {latex} | none

Interpret LaTex instructions. This property controls whether MATLAB interprets certain characters in the String property as LaTex instructions (default) or displays all characters literally. See the String property for a list of support LaTex instructions.

Interruptible          {on} | off

Callback routine interruption mode. The Interruptible property controls whether a Text callback routine can be interrupted by subsequently invoked callback routines. Text objects have four properties that define callback routines: ButtonDownFcn, CreateFcn, and DeleteFcn. See the Executionqueue property for information on how MATLAB executes callback routines.

Parent                 handle

Text object's parent. The handle of the Text object's parent object. The parent of a Text object is the Axes in which it is displayed. You can move a Text object to another Axes by setting this property to the handle of the new parent.

Position               [x,y,[z]]

Location of Text. A two- or three-element vector, [x y [z]], that specifies the location of the text in three dimensions. If you omit the z value, it defaults to 0. All measurements are in units specified by the Units property. Initial value is [0 0 0].

Rotation               scalar (default = 0)

Text orientation. This property determines the orientation of the Text string. Specify values of rotation in degrees (positive angles cause counterclockwise rotation).

Selected               on | {off}

Is object selected. When this property is on. MATLAB displays selection handles if the SelectionHighlight property is also on. You can, for example, define the ButtonDownFcn to set this property, allowing users to select the object with the mouse.

SelectionHighlight     {on} | off

Objects highlight when selected. When the Selected property is on, MATLAB indicates the selected state by drawing four edge handles and four corner handles. When SelectionHighlight is off, MATLAB does not draw the handles.

String                 string

The Text string. Specify this property as a quoted string for single-line strings, or as a cell array of strings or a padded string matrix for multiline strings. MATLAB displays this string at the specified location. Vertical slash characters are not interpreted as linebreaks in Text strings, and are drawn as part of the Text string.

When the Text Interpreter property is Tex (the default), you can use a subset of Tex commands embedded in the string to produce special characters such as Greek letters and mathematical symbols. The following table lists these characters and the character sequence used to define them.

Character

Symbol

Character

Symbol

Character

Symbol

Sequence

Sequence

Sequence

\alpha

\upsilon

\sim

~

\beta

\phi

\leq

\gamma

\chi

\infty

\delta

\psi

\clubsuit

\epsilon

\omega

\diamondsuit

\zeta

\Gamma

\heartsuit

\eta

\Delta

\spadesuit

\theta

\Theta

\leftrightarrow

\vartheta

\Lambda

\leftarrow

\iota

\Xi

\uparrow

\kappa

\Pi

\rightarrow

\lambda

\Sigma

\downarrow

\mu

µ

\Upsilon

\circ

º

\nu

\Phi

\pm

±

\xi

\Psi

\geq

\pi

\Omega

\propto

\rho

\forall

\partial

\sigma

\exist

\bullet

\varsigma

\ni

\

\div

÷

\tau

\cong

\neq

\equiv

\approx

\aleph

\Im

\Re

\wp

\otimes

\oplus

\oslash

\cap

\cup

\supseteq

\supset

\subseteq

\subset

\int

\in

\o

You can also specify stream modifiers that control the font used. The first four modifiers are mutually exclusive. However, you can use \fontname in combination with one of the other modifiers:

Stream modifiers remain in effect until the end of the string or only within the context defined by braces { }.

The subscript character "_" and the superscript character "^" modify the character or substring defined in braces immediately following.

To print the special characters used to define the Tex strings when Interpreter is Tex, prefix them with the backslash "\" character: \\, \{, \} \_, \^. See the "Example" section for more information.

When Interpreter is none, no characters in the String are interpreted, and all are displayed when the text is drawn.

Tag                    string

User-specified object label. The Tag property provides a means to identify graphics objects with a user-specified label. This is particularly useful when constructing interactive graphics programs that would otherwise need to define object handles as global variables or pass them as arguments between callback routines. You can define Tag as any string.

Type                   string (read only)

Class of graphics object. For Text objects, Type is always the string 'text'.

Units                  pixels | normalized | inches | centimeters |
points | {data}

Units of measurement. This property specifies the units MATLAB uses to interpret the Extent and Position properties. All units are measured from the lower-left corner of the Axes plotbox. Normalized units map the lower-left corner of the rectangle defined by the Axes to (0,0) and the upper-right corner to (1.0,1.0). pixels, inches, centimeters, and points are absolute units (1 point = 1/72 inch). data refers to the data units of the parent Axes.

If you change the value of Units, it is good practice to return it to its default value after completing your computation so as not to affect other functions that assume Units is set to the default value.

UserData               matrix

User-specified data. Any data you want to associate with the Text object. MATLAB does not use this data, but you can access it using set and get.

VerticalAlignment      top | cap | {middle} | baseline | bottom

Vertical alignment of Text. This property specifies the vertical justification of the text string. It determines where MATLAB places the string with regard to the value of the Position property. The possible values mean:

Visible                {on} | off

Text visibility. By default, all Text is visible. When set to off, the Text is not visible, but still exists and you can query and set its properties.

See Also

gtext, int2str, num2str, title, xlabel, ylabel, zlabel



[ Previous | Help Desk | Next ]