Text - Axes text appearance and behavior - MATLAB (original) (raw)

Text Properties

Axes text appearance and behavior

Text properties control the appearance and behavior of a Text object. By changing property values, you can modify certain aspects of the text. Use dot notation to query and set properties.

t = text(0.5,0.5,'text here'); s = t.FontSize; t.FontSize = 12;

expand all

Since R2023b

Series index, specified as a positive whole number or"none". This property is useful for reassigning the font color so that it matches the colors of other objects.

If the SeriesIndex value is a number, MATLAB uses that number to calculate an index for assigning the color when you call functions such as text,title, or xlabel to create text in a chart. The index refers to the rows of the array stored in theColorOrder property of the axes. Any objects in the axes that have the same SeriesIndex number will have the same color.

A SeriesIndex value of "none" corresponds to a neutral color that does not participate in the indexing scheme.

How Manual Color Assignment Overrides SeriesIndex Behavior

To manually control the font color, set the Color property of the Text object to a color value, such as a color name or RGB triplet.

When you manually set the font color, MATLAB does not use automatic color selection for that object, and it allows your color to persist, regardless of the value of theSeriesIndex property. TheColorMode property indicates whether the color has been set manually (by you) or automatically. A value of"manual" indicates manual selection, and a value of "auto" indicates automatic selection.

To enable automatic selection, set theSeriesIndex property to a positive whole number, and set the ColorMode property to"auto".

In some cases, MATLAB sets the SeriesIndex property to0, which also disables automatic color selection.

Font

expand all

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Font size units, specified as one of the values in this table.

Units Description
'points' Points. One point equals 1/72 inch.
'inches' Inches.
'centimeters' Centimeters.
'normalized' Interpret font size as a fraction of the axes plot box height. If you resize the axes, the font size modifies accordingly. For example, if theFontSize is0.1 in normalized units, then the text is 1/10 of the plot box height.
'pixels' Pixels.On Windows® and Macintosh systems, the size of a pixel is 1/96th of an inch. This size is independent of your system resolution.On Linux® systems, the size of a pixel is determined by your system resolution.

If you set both the font size and the font units in one function call, you must set the FontUnits property first so that the axes correctly interprets the specified font size.

Text Box

expand all

Text orientation, specified as a scalar value in degrees. A rotation value of 0 degrees makes the text horizontal. For vertical text, set this property to 90 or -90. Positive values rotate the text counterclockwise. Negative values rotate the text clockwise.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Color of box outline, specified as an RGB triplet, a hexadecimal color code, a color name, or a short name.

For a custom color, specify an RGB triplet or a hexadecimal color code.

Alternatively, you can specify some common colors by name. This table lists the named color options, the equivalent RGB triplets, and the hexadecimal color codes.

Color Name Short Name RGB Triplet Hexadecimal Color Code Appearance
"red" "r" [1 0 0] "#FF0000" Sample of the color red
"green" "g" [0 1 0] "#00FF00" Sample of the color green
"blue" "b" [0 0 1] "#0000FF" Sample of the color blue
"cyan" "c" [0 1 1] "#00FFFF" Sample of the color cyan
"magenta" "m" [1 0 1] "#FF00FF" Sample of the color magenta
"yellow" "y" [1 1 0] "#FFFF00" Sample of the color yellow
"black" "k" [0 0 0] "#000000" Sample of the color black
"white" "w" [1 1 1] "#FFFFFF" Sample of the color white
"none" Not applicable Not applicable Not applicable No color

This table lists the default color palettes for plots in the light and dark themes.

Palette Palette Colors
"gem" — Light theme default_Before R2025a: Most plots use these colors by default._ Sample of the "gem" color palette
"glow" — Dark theme default Sample of the "glow" color palette

You can get the RGB triplets and hexadecimal color codes for these palettes using the orderedcolors and rgb2hex functions. For example, get the RGB triplets for the "gem" palette and convert them to hexadecimal color codes.

RGB = orderedcolors("gem"); H = rgb2hex(RGB);

Before R2023b: Get the RGB triplets using RGB = get(groot,"FactoryAxesColorOrder").

Before R2024a: Get the hexadecimal color codes using H = compose("#%02X%02X%02X",round(RGB*255)).

Example: 'blue'

Example: [0 0 1]

Example: '#0000FF'

Color of text box background, specified as an RGB triplet, a hexadecimal color code, a color name, or a short name.

For a custom color, specify an RGB triplet or a hexadecimal color code.

Alternatively, you can specify some common colors by name. This table lists the named color options, the equivalent RGB triplets, and the hexadecimal color codes.

Color Name Short Name RGB Triplet Hexadecimal Color Code Appearance
"red" "r" [1 0 0] "#FF0000" Sample of the color red
"green" "g" [0 1 0] "#00FF00" Sample of the color green
"blue" "b" [0 0 1] "#0000FF" Sample of the color blue
"cyan" "c" [0 1 1] "#00FFFF" Sample of the color cyan
"magenta" "m" [1 0 1] "#FF00FF" Sample of the color magenta
"yellow" "y" [1 1 0] "#FFFF00" Sample of the color yellow
"black" "k" [0 0 0] "#000000" Sample of the color black
"white" "w" [1 1 1] "#FFFFFF" Sample of the color white
"none" Not applicable Not applicable Not applicable No color

This table lists the default color palettes for plots in the light and dark themes.

Palette Palette Colors
"gem" — Light theme default_Before R2025a: Most plots use these colors by default._ Sample of the "gem" color palette
"glow" — Dark theme default Sample of the "glow" color palette

You can get the RGB triplets and hexadecimal color codes for these palettes using the orderedcolors and rgb2hex functions. For example, get the RGB triplets for the "gem" palette and convert them to hexadecimal color codes.

RGB = orderedcolors("gem"); H = rgb2hex(RGB);

Before R2023b: Get the RGB triplets using RGB = get(groot,"FactoryAxesColorOrder").

Before R2024a: Get the hexadecimal color codes using H = compose("#%02X%02X%02X",round(RGB*255)).

Example: 'blue'

Example: [0 0 1]

Example: '#0000FF'

Line style of box outline, specified as one of the options in this table.

Line Style Description Resulting Line
"-" Solid line Sample of solid line
"--" Dashed line Sample of dashed line
":" Dotted line Sample of dotted line
"-." Dash-dotted line Sample of dash-dotted line, with alternating dashes and dots
"none" No line No line

Width of box outline, specified as a scalar numeric value in point units. One point equals 1/72 inch.

Example: 1.5

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

The space around the text within the text box, specified as scalar numeric value in point units.

MATLAB uses the Extent property value plus theMargin property value to determine the size of the text box.

Example: 8

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Clipping of the text to the axes plot box, specified as'on' or 'off', or as numeric or logical 1 (true) or0 (false). A value of'on' is equivalent to true, and'off' is equivalent to false. Thus, you can use the value of this property as a logical value. The value is stored as an on/off logical value of type matlab.lang.OnOffSwitchState.

Note

If the Clipping property of the associated axes is set to 'on', which is the default, then each individual object controls its own clipping behavior. If theClipping property of the axes is set to'off', then MATLAB does not clip any objects in the axes, regardless of the Clipping property of the individual object.

Position

expand all

Data Types: double | single | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

This property is read-only.

Size and location of the rectangle that encloses the text, not including the margin, returned as a four-element vector of the form [left bottom width height]. The first two elements,left and bottom, define the position of the lower left corner of the rectangle. The last two elements,width and height, define the dimensions of the rectangle.

By default, the extent value is defined in data units. To change the units, use the Units property.

Example: [0.5 0.5 0.4 0.2]

Since R2023b

Include the anchor point of the Text object in the automatic selection of axes limits, specified as "on" or "off", or as numeric or logical 1 (true) or 0 (false). The value is stored as an on/off logical value of type matlab.lang.OnOffSwitchState.

The Position property defines the location of the anchor point.

Setting this property to "on" can help you to locate and fine-tune the position of your text. To exclude the anchor point from the automatic limits selection, set this property to"off".

Interactivity

expand all

Interactive edit mode, specified as 'on' or'off', or as numeric or logical 1 (true) or 0 (false). A value of 'on' is equivalent to true, and 'off' is equivalent to false. Thus, you can use the value of this property as a logical value. The value is stored as an on/off logical value of type matlab.lang.OnOffSwitchState.

Interactions, specified as an array of interaction objects or an empty array. The interactions you specify are available within your chart through gestures. For example, an editInteraction object enables clicking on text to edit.

The Interactions property does not appear in the property editor.

Callbacks

Callback Execution Control

expand all

This property is read-only.

Parent/Child

expand all

Parent, specified as an Axes, PolarAxes, Group, or Transform object.

The object has no children. You cannot set this property.

Identifiers

expand all

This property is read-only.

Type of graphics object, returned as 'text'. Use this property to find all objects of a given type within a plotting hierarchy, for example, searching for the type using findobj.

Object identifier, specified as a character vector or string scalar. You can specify a unique Tag value to serve as an identifier for an object. When you need access to the object elsewhere in your code, you can use the findobj function to search for the object based on the Tag value.

Version History

Introduced before R2006a

expand all

The default Color property value in the light theme has changed. This table lists the changes.

Type of Text R2024b Color R2025a Color
Text labels created with the text function [0 0 0] [0.1294 0.1294 0.1294]
Plot titles created with the title andsubtitle functions [0 0 0] [0.1294 0.1294 0.1294]
Axes labels, such as those created with the xlabel,ylabel, andzlabel functions [0.15 0.15 0.15] [0.1294 0.1294 0.1294]

The FontSmoothing property has no effect and will be removed in a future release. You can set or get the value of this property without warning, but all text is smooth regardless of the property value. This property removal was announced in R2022a.

Create a text object whose anchor point location is included in the axes limits selection. To include an anchor point in the automatic limits selection, set theAffectAutoLimits property of the text object to"on".

Control how Text objects vary in color by setting theSeriesIndex property. This property is useful when you want to match the colors of different objects in the axes.

Setting or getting UIContextMenu property is not recommended. Instead, use the ContextMenu property, which accepts the same type of input and behaves the same way as theUIContextMenu property.

There are no plans to remove the UIContextMenu property, but it is no longer listed when you call the set, get, orproperties functions on the Text object.