Accelerating the pace of engineering and science

Documentation Center

• Trial Software

Text Properties

Text properties

Creating Text Objects

Use text to create text objects.

Modifying Properties

You can set and query graphics object properties using the property editor or the set and get commands.

• Property Editor is an interactive tool that enables you to see and change object property values.

• The set and get commands enable you to set and query the values of properties.

To change the default values of properties, see Setting Default Property Values.

Text Property Descriptions

This section provides a description of properties. Curly braces { } enclose default values.

Annotation

Handle of Annotation object. The Annotation property enables you to specify whether this text object is represented in a figure legend.

Querying the Annotation property returns the handle of an hg.Annotation object. The hg.Annotation object has a property called LegendInformation, which contains an hg.LegendEntry object.

Once you have obtained the hg.LegendEntry object, you can set its IconDisplayStyle property to control whether the text object is displayed in a figure legend:

IconDisplayStyle ValuePurpose
onRepresent this text object in a legend (default)
offDo not include this text object in a legend
childrenSame as on because text objects do not have children

Setting the IconDisplayStyle property

Set the IconDisplayStyle of a graphics object with handle hobj to off:

hAnnotation = get(hobj,'Annotation');
hLegendEntry = get(hAnnotation,'LegendInformation');
set(hLegendEntry,'IconDisplayStyle','off')

Using the IconDisplayStyle property

BackgroundColor

ColorSpec | {none}

Color of text extent rectangle. Defines a color for the rectangle that encloses the text Extent plus the text Margin. For example, the following code creates a text object that labels a plot and sets the background color to light green.

text(3*pi/4,sin(3*pi/4),...
['sin(3*pi/4) = ',num2str(sin(3*pi/4))],...
'HorizontalAlignment','center',...
'BackgroundColor',[.7 .9 .7]);


For additional features, see the following properties:

• EdgeColor — Color of the rectangle's edge (none by default).

• LineStyle — Style of the rectangle's edge line (first set EdgeColor)

• LineWidth — Width of the rectangle's edge line (first set EdgeColor)

• Margin — Increase the size of the rectangle by adding a margin to the existing text extent rectangle. This margin is added to the text extent rectangle to define the text background area that is enclosed by the EdgeColor rectangle. Note that the text extent does not change when you change the margin; only the rectangle displayed when you set the EdgeColor property and the area defined by the BackgroundColor change.

See also Drawing Text in a Box in the MATLAB® Graphics documentation for an example using background color with contour labels.

BeingDeleted

This object is being deleted. Mechanism to determine if objects are in the process of being deleted. MATLAB sets the BeingDeleted property to on when the object's delete function callback is called (see the DeleteFcn property). It remains set to on while the delete function executes, after which the object no longer exists.

For example, an object's delete function calls other functions that act on a number of different objects. If a function does not need to perform an action on an about-be-deleted object, it can check the object's BeingDeleted property before acting.

BusyAction

cancel | {queue}

Callback queuing

Determines how MATLAB handles the execution of interrupting callbacks.

A running callback is the currently executing callback. The interrupting callback is the callback that tries to interrupt the running callback. The BusyAction property of the interrupting callback determines how MATLAB handles its execution. When the BusyAction property is set to:

• 'queue' — Puts the interrupting callback in a queue to be processed after the running callback finishes execution.

• 'cancel' — Discards the interrupting callback as MATLAB finishes execution.

For information about how the Interruptible property of the callback controls whether other callbacks can interrupt the running callback, see the Interruptible property description.

ButtonDownFcn

function handle | cell array containing function handle and additional arguments | string (not recommended)

Button press callback function. Executes whenever you press a mouse button while the pointer is over the text object.

See the figure's SelectionType property to determine if modifier keys were also pressed.

Set this property to a function handle that references the callback. The function must define at least two input arguments (handle of object associated with the button down event and an event structure, which is empty for this property).

The following example shows how to access the callback object's handle as well as the handle of the figure that contains the object from the callback function.

function button_down(src,evnt)
% src - the object that is the source of the event
% evnt - empty for this property
sel_typ = get(gcbf,'SelectionType')
switch sel_typ
case 'normal'
disp('User clicked left-mouse button')
set(src,'Selected','on')
case 'extend'
disp('User did a shift-click')
set(src,'Selected','on')
case 'alt'
disp('User did a control-click')
set(src,'Selected','on')
set(src,'SelectionHighlight','off')
end
end

Suppose h is the handle of a text object and the button_down function is on your MATLAB path. The following statement assigns the button_down function to the ButtonDownFcn property:

set(h,'ButtonDownFcn',@button_down)

For information on the syntax of callback functions, see Function Handle Callbacks.

Children

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 the predefined names, specifying the text color. The default value is [0 0 0] (black). See the ColorSpec reference page for more information on specifying color.

CreateFcn

function handle | cell array containing function handle and additional arguments | string (not recommended)

Callback function executed during object creation. Executes when MATLAB creates a text object. You must define this property as a default value for text or in a call to the text function that creates a new text object. For example, the statement:

set(0,'DefaultTextCreateFcn',@text_create)


defines a default value on the root level that sets the figure Pointer property to crosshairs whenever you create a text object. The callback function must be on your MATLAB path when you execute the above statement.

function text_create(src,evnt)
% src - the object that is the source of the event
% evnt - empty for this property
set(gcbf,'Pointer','crosshair')
end

MATLAB executes this function after setting all text properties. Setting this property on an existing text object has no effect. The function must define at least two input arguments (handle of object created and an event structure, which is empty for this property).

The handle of the object whose CreateFcn is being executed is passed by MATLAB as the first argument to the callback function and is also accessible through the root CallbackObject property, which you can query using gcbo.

For information on the syntax of callback functions, see Function Handle Callbacks.

DeleteFcn

function handle | cell array containing function handle and additional arguments | string (not recommended)

Delete text callback function. Executes when you delete the text object (for example, when you issue a delete command or clear the axes cla or figure clf).

For example, the following function displays object property data before the object is deleted.

function delete_fcn(src,evnt)
% src - the object that is the source of the event
% evnt - empty for this property
obj_tp = get(src,'Type');
disp([obj_tp, ' object deleted'])
disp('Its user data is:')
disp(get(src,'UserData'))
end

MATLAB executes the function before deleting the object's properties so these values are available to the callback function. The function must define at least two input arguments (handle of object being deleted and an event structure, which is empty for this property).

The handle of the object whose DeleteFcn is being executed is passed by MATLAB as the first argument to the callback function and is also accessible through the root CallbackObject property, which you can query using gcbo.

For information on the syntax of callback functions, see Function Handle Callbacks.

DisplayName

string

String used by legend. The legend function uses the DisplayName property to label the text object in the legend. The default is an empty string.

• If you specify string arguments with the legend function, MATLAB set DisplayName to the corresponding string and uses that string for the legend.

• If DisplayName is empty, legend creates a string of the form, ['data' n], where n is the number assigned to the object based on its location in the list of legend entries. However, legend does not set DisplayName to this string.

• If you edit the string directly in an existing legend, MATLAB set DisplayName to the edited string.

• If you specify a string for the DisplayName property and create the legend using the figure toolbar, then MATLAB uses the string defined by DisplayName.

• To add a legend programmatically that uses the DisplayName string, call legend with the toggle or show option.

EdgeColor

ColorSpec | {none}

Color of edge drawn around text extent rectangle plus margin. Specifies the color of a box drawn around the text Extent plus the text Margin. For example, the following code draws a red rectangle around text that labels a plot.

text(3*pi/4,sin(3*pi/4),...
'\leftarrowsin(t) = .707',...
'EdgeColor','red');


For additional features, see the following properties:

• BackgroundColor — Color of the rectangle's interior (none by default)

• LineStyle — Style of the rectangle's edge line (first set EdgeColor)

• LineWidth — Width of the rectangle's edge line (first set EdgeColor)

• Margin — Increases the size of the rectangle by adding a margin to the area defined by the text extent rectangle. This margin is added to the text extent rectangle to define the text background area that is enclosed by the EdgeColor rectangle. Note that the text extent does not change when you change the margin; only the rectangle displayed when you set the EdgeColor property and the area defined by the BackgroundColor change.

Editing

on | {off}

Enable or disable editing mode. When this property is off (the default ), you cannot edit the text string interactively (i.e., you must change the String property to change the text). When you set this property to on, MATLAB enables editing and places an insert cursor wherever the mouse is within the text. To apply the new text string, do any one of the following:

• Press the Esc key.

• Click anywhere away from the text string.

• Reset the Editing property to off.

MATLAB updates the String property to contain the new text and resets the Editing property to off. You must reset the Editing property to on to resume editing.

EraseMode

{normal} | none | xor | background

Erase mode. Controls the technique MATLAB uses to draw and erase text objects. Alternative erase modes are useful for creating animated sequences where controlling the way individual objects are redrawn is necessary to improve performance and obtain the desired effect.

• normal — Redraw the affected region of the display, performing the three-dimensional analysis necessary to ensure that all objects are rendered correctly. This mode produces the most accurate picture, but is the slowest. The other modes are faster, but do not perform a complete redraw and are therefore less accurate.

• none — Do not erase the text when it is moved or destroyed. While the object is still visible on the screen after erasing with EraseMode none, you cannot print it because MATLAB stores no information about its former location.

• xor — Draw and erase the text by performing an exclusive OR (XOR) with each pixel index of the screen beneath it. When the text is erased, it does not damage the objects beneath it. However, when text is drawn in xor mode, its color depends on the color of the screen beneath it. It is correctly colored only when it is over axes background Color, or the figure background Color if the axes Color is none.

• background — Erase the text by drawing it in the axes background Color, or the figure background Color if the axes Color is none. This damages objects that are behind the erased text, but text is always properly colored.

Printing with Nonnormal Erase Modes

MATLAB always prints figures as if the EraseMode of all objects is normal. This means graphics objects created with EraseMode set to none, xor, or background can look different on screen than on paper. On screen, MATLAB mathematically combines layers of colors (for example, performing an XOR on a pixel color with that of the pixel behind it) and ignore three-dimensional sorting to obtain greater rendering speed. However, these techniques are not applied to the printed output.

You can use the getframe command or other screen capture applications to create an image of a figure containing nonnormal mode objects.

Extent

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

[left,bottom,width,height]


If the Units property is data (the default), left and bottom are the x- and y-coordinates of the lower left corner of the text Extent.

For all other values of Units, left and bottom are the distance from the lower left corner of the axes Position rectangle to the lower left corner of the text Extent. 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

name (such as Courier) | FixedWidth

Font family. Specifies 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.

Specifying a Fixed-Width Font

If you want text to use a fixed-width font that looks good in any locale, you should set FontName to the string FixedWidth:

set(text_handle,'FontName','FixedWidth')


This eliminates the need to hard-code the name of a fixed-width font, which might not display text properly on systems that do not use ASCII character encoding (such as in Japan where multibyte character sets are used). A properly written MATLAB application that needs to use a fixed-width font should set FontName to FixedWidth (note that this string is case sensitive) and rely on FixedWidthFontName to be set correctly in the end user's environment.

End users can adapt a MATLAB application to different locales or personal environments by setting the root FixedWidthFontName property to the appropriate value for that locale from startup.m.

Note that setting the root FixedWidthFontName property causes an immediate update of the display to use the new font.

Bitmapped fonts (e.g., Courier) cannot be rotated on the display. Therefore, when you specify a bitmapped font with the FontName property, this text might not be rotated correctly, for example, when used as the y-axis label. To avoid problems with bitmapped fonts, use TrueType fonts. For example, you might have a TrueType font named Courier New that you can use instead of Courier. See your system documentation for information on which fonts are installed on your system.

FontSize

size in FontUnits

Font size. Specifies the font size to use for text in units determined by the FontUnits property. The default is 10 points. 1 point = 1/72 inch.

FontWeight

{normal} | bold | light | demi

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 — 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 — Absolute units. 1 point = 1/72 inch.

Note that if you are setting both the FontSize and the FontUnits in one function call, you must set the FontUnits property first so that MATLAB can correctly interpret the specified FontSize.

HandleVisibility

{on} | callback | off

Control access to object's handle. Determines when an object's handle is visible in its parent's list of children. HandleVisibility is useful for preventing command-line users from accidentally drawing into or deleting a figure that contains only user interface devices (such as a dialog box).

• on — Handles are always visible.

• callback — Handles are visible from within callback routines or functions invoked by callback routines, but not from within functions invoked from the command line. This provides a means to protect GUIs from command-line users, while allowing callback routines to have access to object handles.

• off — Handles are invisible at all times. Use this option when a callback invokes a function that could damage the GUI (such as evaluating a user-typed string). This option temporarily hides its own handles during the execution of that function.

When a handle is not visible in its parent's list of children, it cannot be returned by functions that obtain handles by searching the object hierarchy or querying handle properties. This includes 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.

• Axes do not appear in their parent's CurrentAxes property.

You can set the root ShowHiddenHandles property to on to 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.

HitTest

{on} | off

Selectable by mouse click. Determines if the text can become the current object (as returned by the gco command and the figure CurrentObject property) as a result of a mouse click on the text. If HitTest is off, clicking the text selects the object below it (which is usually the axes containing it).

For example, suppose you define the button down function of an image (see the ButtonDownFcn property) to display text at the location you click with the mouse.

First define the callback routine.

function bd_function
pt = get(gca,'CurrentPoint');
text(pt(1,1),pt(1,2),pt(1,3),...
'{\fontsize{20}\oplus} The spot to label',...
'HitTest','off')


Now display an image, setting its ButtonDownFcn property to the callback routine.

load earth
image(X,'ButtonDownFcn','bd_function'); colormap(map)


When you click the image, MATLAB displays the text string at that location. With HitTest set to off, existing text cannot intercept any subsequent button down events that occur over the text. This enables the image's button down function to execute.

HorizontalAlignment

{left} | center | right

Horizontal alignment of text. 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. The following picture illustrates the alignment options.

See the Extent property for related information.

Interpreter

latex | {tex} | none

Interpret TeXinstructions. Controls whether MATLAB interprets certain characters in the String property as TeX instructions (default) or displays all characters literally.

• latex — Supports a basic subset of the LaTeX markup language.

• tex — Supports a subset of plain TeX markup language. See the String property for a list of supported TeX instructions.

• none — Displays literal characters.

LaTeX Interpreter

To enable the LaTeX interpreter for text objects, set the Interpreter property to latex. For example, the following statement displays an equation in a figure at the point [.5 .5], and enlarges the font to 16 points.

text('Interpreter','latex',...
'String','$$\int_0^x\!\int_y dF(u,v)$$',...
'Position',[.5 .5],...
'FontSize',16)


 Note:   The maximum size of the string that you can use with the LaTeX interpreter is 1200 characters. For multiline strings, reduce this amount by about 10 characters per line.

The following references may be useful to people who are not familiar with TeX.

• Donald E. Knuth, The TEXbook, Addison Wesley, 1986.

Interruptible

off | {on}

Callback routine interruption

Controls whether MATLAB can interrupt an object's callback function when subsequent callbacks attempt to interrupt it.

For Graphics objects, the Interruptible property affects only the callbacks for theButtonDownFcn property. A running callback is the currently executing callback. The interrupting callback is the callback that tries to interrupt the running callback. MATLAB handles both the callbacks based on the Interruptible property of the object of the running callback.

When the Interruptible property is set to:

• 'off', MATLAB finishes execution of the running callback without any interruptions

• 'on', these conditions apply:

• If there is a drawnow, figure, getframe, waitfor, or pause command in the running callback, then MATLAB executes the interrupting callbacks which are already in the queue and returns to finish execution of the current callback.

• If one of the above functions is not in the running callback, then MATLAB finishes execution of the current callback without any interruption.

BusyAction property of the object of interrupting callback determines whether the callback should be ignored or should be put in the queue.

Setting Interruptible property to on (default), allows a callback from other graphics objects to interrupt callback functions originating from this object.

 Note:   MATLAB does not save the state of properties or the display when an interruption occurs. For example, the handle returned by the gca or gcf command may be changed as another callback is executed.

After the function that interrupts a callback completes, the callback resumes execution where it halted when interrupted. For more information, see Control Callback Execution and Interruption.

LineStyle

{-} | -- | : | -. | none

Edge line type. Specifies the line style used to draw the edges of the text Extent.

For example, the following code draws a red rectangle with a dotted line style around text that labels a plot.

text(3*pi/4,sin(3*pi/4),...
'\leftarrowsin(t) = .707',...
'EdgeColor','red',...
'LineWidth',2,...
'LineStyle',':');


For additional features, see the following properties:

• BackgroundColor — Color of the rectangle's interior (none by default)

• EdgeColor — Color of the rectangle's edge (none by default)

• LineWidth — Width of the rectangle's edge line (first set EdgeColor)

• Margin — Increases the size of the rectangle by adding a margin to the existing text extent rectangle. This margin is added to the text extent rectangle to define the text background area that is enclosed by the EdgeColor rectangle. Note that the text extent does not change when you change the margin; only the rectangle displayed when you set the EdgeColor property and the area defined by the BackgroundColor change.

LineWidth

scalar (points)

Width of line used to draw text extent rectangle. When you set the text EdgeColor property to a color (the default is none), MATLAB displays a rectangle around the text Extent. Use the LineWidth property to specify the width of the rectangle edge. For example, the following code draws a red rectangle around text that labels a plot and specifies a line width of 3 points:

text(3*pi/4,sin(3*pi/4),...
'\leftarrowsin(t) = .707',...
'EdgeColor','red',...
'LineWidth',3);


For additional features, see the following properties:

• BackgroundColor — Color of the rectangle's interior (none by default)

• EdgeColor — Color of the rectangle's edge (none by default)

• LineStyle — Style of the rectangle's edge line (first set EdgeColor)

• Margin — Increases the size of the rectangle by adding a margin to the existing text extent rectangle. This margin is added to the text extent rectangle to define the text background area that is enclosed by the EdgeColor rectangle. Note that the text extent does not change when you change the margin; only the rectangle displayed when you set the EdgeColor property and the area defined by the BackgroundColor change.

Margin

scalar (pixels)

Distance between the text extent and the rectangle edge. When you specify a color for the BackgroundColor or EdgeColor text properties, MATLAB draws a rectangle around the area defined by the text Extent plus the value specified by the Margin. For example, the following code displays a light green rectangle with a 10-pixel margin.

text(5*pi/4,sin(5*pi/4),...
['sin(5*pi/4) = ',num2str(sin(5*pi/4))],...
'HorizontalAlignment','center',...
'BackgroundColor',[.7 .9 .7],...
'Margin',10);


For additional features, see the following properties:

• BackgroundColor — Color of the rectangle's interior (none by default)

• EdgeColor — Color of the rectangle's edge (none by default)

• LineStyle — Style of the rectangle's edge line (first set EdgeColor)

• LineWidth — Width of the rectangle's edge line (first set EdgeColor)

See how margin affects text extent properties

This example enables you to change the values of the Margin property and observe the effects on the BackgroundColor area and the EdgeColor rectangle.

Click to view in editorClick to view in editor — This link opens the MATLAB editor with the following example.

Click to run exampleClick to run example — Use your scroll wheel to vary the Margin.

Parent

handle of axes, hggroup, or hgtransform

Parent of text object. Handle of the text object's parent. The parent of a text object is the axes, hggroup, or hgtransform object that contains it.

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. 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 set to 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 are highlighted 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

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 line breaks in text strings, and are drawn as part of the text string. See Mathematical Symbols, Greek Letters, and TeX Characters for an example.

 Note:   The words default, factory, and remove are reserved words that will not appear in a figure when quoted as a normal string. In order to display any of these words individually, type '\reserved_word' instead of 'reserved_word'.

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. This table lists these characters and the character sequences used to define them.

Character Sequence

Symbol

Character Sequence

Symbol

Character Sequence

Symbol

\alpha

α

\upsilon

υ

\sim

~

\angle

\phi

Φ

\leq

\ast

*

\chi

χ

\infty

\beta

β

\psi

ψ

\clubsuit

\gamma

γ

\omega

ω

\diamondsuit

\delta

δ

\Gamma

Γ

\heartsuit

\epsilon

ɛ

\Delta

Δ

\zeta

ζ

\Theta

Θ

\leftrightarrow

\eta

η

\Lambda

Λ

\leftarrow

\theta

Θ

\Xi

Ξ

\Leftarrow

\vartheta

ϑ

\Pi

Π

\uparrow

\iota

ι

\Sigma

Σ

\rightarrow

\kappa

κ

\Upsilon

ϒ

\Rightarrow

\lambda

λ

\Phi

Φ

\downarrow

\mu

µ

\Psi

Ψ

\circ

º

\nu

ν

\Omega

Ω

\pm

±

\xi

ξ

\forall

\geq

\pi

π

\exists

\propto

\rho

ρ

\ni

\partial

\sigma

σ

\cong

\bullet

\varsigma

ς

\approx

\div

÷

\tau

τ

\Re

\neq

\equiv

\oplus

\aleph

\Im

\cup

\wp

\otimes

\subseteq

\oslash

\cap

\in

\supseteq

\supset

\lceil

\subset

\int

\cdot

·

\o

ο

\rfloor

\neg

¬

\nabla

\lfloor

\times

x

\ldots

...

\perp

\surd

\prime

´

\wedge

\varpi

ϖ

\0

\rceil

\rangle

\mid

|

\vee

\langle

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

• \bf — Bold font

• \it — Italic font

• \sl — Oblique font (rarely available)

• \rm — Normal font

• \fontname{fontname} — Specify the name of the font family to use.

• \fontsize{fontsize} — Specify the font size in FontUnits.

• \color(colorSpec) — Specify color for succeeding characters

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

Specifying Text Color in TeX Strings

Use the \color modifier to change the color of characters following it from the previous color (which is black by default). Syntax is:

• \color{colorname} — Use for the eight basic named colors (red, green, yellow, magenta, blue, black, white), and plus the four Simulink® colors (gray, darkGreen, orange, and lightBlue).

Note that short names (one-letter abbreviations) for colors are not supported by the \color modifier.

• \color[rgb]{r g b} — Use to specify an RGB triplet with values between 0 and 1 as a cell array

For example:

text(.1,.5,['\fontsize{16}black '...
'{\color{magenta}magenta '...
'\color[rgb]{0 .5 .5}teal '...
'\color{red}red} black again'])


Specifying Subscript and Superscript Characters

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: \\, \{, \} \_, \^.

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

When Interpreter is latex, MATLAB provides a complete LaTeX interpreter for text objects. See the Interpreter property for more information.

Tag

string

User-specified object label. Provides a means to identify graphics objects with a user-specified label. The default is an empty string.

Use the Tag property and the findobj function to manipulate specific objects within a plotting hierarchy.

Type

Class of graphics object. String that identifies the class of the graphics object. Use this property to find all objects of a given type within a plotting hierarchy. For text objects, Type is always 'text'.

Associate a context menu with the text. The handle of a uicontextmenu object created in the same figure as the text. Use the uicontextmenu function to create the context menu. MATLAB displays the context menu whenever you right-click over the text.

Units

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

Units of measurement. Specifies the units MATLAB uses to interpret the Extent and Position properties. All units are measured from the lower left corner of the axes plot box.

• 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 — Absolute units. 1 point = 1/72 inch.

• characters — Based on the size of characters in the default system font. The width of one characters unit is the width of the letter x, and the height of one characters unit is the distance between the baselines of two lines of text.

• data — Data units of the parent axes as determined by the data graphed (not the axes Units property, which controls the positioning of the axes within the figure window).

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. Data you want to associate with the text object. The default value is an empty array. MATLAB does not use this data, but you can access it using the set and get commands.

VerticalAlignment

top | cap | {middle} | baseline |
bottom

Vertical alignment of text. Specifies the vertical justification of the text string. It determines where MATLAB places the string vertically with regard to the points specified by the Position property.

• top — Place the top of the string' s Extent rectangle at the specified y-position.

• cap — Place the string so that the top of a capital letter is at the specified y-position.

• middle — Place the middle of the string at the specified y-position.

• baseline — Place font baseline at the specified y-position.

• bottom — Place the bottom of the string's Extent rectangle at the specified y-position.

The following picture illustrates the alignment options.