Documentation Center

  • Trial Software
  • Product Updates

title

Add title to current axes

Syntax

Description

example

title(str) adds the title consisting of a string, str, at the top and in the center of the current axes. Each axes graphics object has one predefined title.

example

title(str,Name,Value) additionally specifies the title properties using one or more Name,Value pair arguments.

example

title(axes_handle,___) adds the title to the axes specified by axes_handle. This syntax allows you to specify the axes to which to add a title. axes_handle can precede any of the input argument combinations in the previous syntaxes.

example

h = title(___) returns the handle to the text object used as the title. The handle is useful when making future modifications to the title.

Examples

expand all

Add Title to Current Figure

Create a figure and display a title in the current axes.

figure
plot((1:10).^2)
title('My Title')

You also can call title with a function that returns a string. For example, the date function returns a string containing today's date.

title(date)

MATLAB® sets the output of date as the axes title.

Include Variable's Value in Title

Include the value of variable c in a title.

figure
plot((1:10).^2)
f = 70;
c = (f-32)/1.8;
title(['Temperature is ',num2str(c),' C'])

Create Multicolored Title Using TeX Markup

In a TeX string, use the color modifier \color to change the color of characters following it from the previous color.

figure
plot((1:10).^2)
title(['\fontsize{16}black {\color{magenta}magenta '...
'\color[rgb]{0 .5 .5}teal \color{red}red} black again'])

Create Colored Title Using Name,Value Pair Argument

Use the Name,Value pair 'Color','m' to set the color of the title to magenta.

figure
plot((1:10).^2)
title('Case number # 3','Color', 'm')

Include Greek Symbols in Title

Use a TeX string to include Greek symbols in a title.

t = (0:0.01:0.2);
y = exp(-25*t);
figure
plot(t,y)
title('y = \ite^{\lambda t}','Color','b')

The 'Interpreter' property must be 'tex' (the default).

Include Superscript or Subscript Character in Title

figure
plot((1:10).^2)
title('\alpha^2 and X_1')

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

Create Multiline Title

Create a multiline title using a multiline cell array.

figure
plot((1:10).^2)
title({'First line';'Second line'})

Display Text As Typed

Set the Interpreter property as 'none' so that the string X_1 is displayed in the figure as typed, without making 1 a subscript of X.

figure
plot((1:10).^2)
title('X_1','Interpreter','none')

MATLAB® displays the string X_1 in the title of the figure.

Add Title to Specific Axes

Create two subplots and return the handles to the axes objects, s(1) and s(2).

figure
s(1) = subplot(2,1,1);
plot((1:10).^2)
s(2) = subplot(2,1,2);
plot((1:10).^3)

Add a title to each subplot by referring to its axes handle, s(1), or s(2).

title(s(1),'Top Plot')
title(s(2),'Bottom Plot')

Add Title and Return Text Handle

Add a title to a plot and return the handle to the text object used as the title.

figure
plot((1:10).^2)
h = title('My Title');

MATLAB® returns the handle in the output variable, h.

Set the color of the title to red, using the handle.

set(h,'Color','red')

Input Arguments

expand all

str — Text to display as titlestring

Text to display as a title, specified as a string. You also can specify the name of a function that returns a string.

Example: 'myTitle'

Example: date

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

axes_handle — Axes handlehandle

Axes handle, which is the reference to an axes object. Use the gca function to get the handle to the current axes, for example, axes_handle = gca;.

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: 'Color','red','FontSize',14 adds a title with red, 14-point font.

In addition to the following, you can specify other text object properties using Name,Value pair arguments. See Text Properties.

'Color' — Text color[0 0 0] (black) (default) | 3-element RGB vector | string

Text color, specified as the comma-separated pair consisting of 'Color' and a 3-element RGB vector or a string containing the short or long name of the color. The RGB vector is a 3-element row vector whose elements specify the intensities of the red, green, and blue components of the color. The intensities must be in the range [0 1].

The following table lists the predefined colors and their RGB equivalents.

RGB Value

Short Name

Long Name

[1 1 0]

y

yellow

[1 0 1]

m

magenta

[0 1 1]

c

cyan

[1 0 0]

r

red

[0 1 0]

g

green

[0 0 1]

b

blue

[1 1 1]

w

white

[0 0 0]

k

black

Example: 'Color',[0 1 0]

Example: 'Color','green'

'FontAngle' — Character slant'normal' (default) | 'italic' | 'oblique'

Character slant, specified as the comma-separated pair consisting of 'FontAngle' and one of these values: 'normal', 'italic', or 'oblique'. MATLAB® uses the FontAngle property to select a font from those available on your particular system. Generally, setting this property to italic or oblique selects a slanted font.

Example: 'FontAngle','italic'

'FontName' — Font name'Helvetica' (default) | string | 'FixedWidth'

Font name, specified as the comma-separated pair consisting of 'FontName' and a string. The string 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.

To use a fixed-width font that looks good in any locale, use the case-sensitive string '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.

Example: 'FontName','Courier'

'FontSize' — Font size10 points (default) | scalar

Font size, specified as the comma-separated pair consisting of 'FontSize' and a scalar in units determined by the FontUnits property. The default value for FontUnits is points.

Example: 'FontSize',12.5

'FontUnits' — Font size units'points' (default) | 'normalized' | 'inches' | 'centimeters' | 'pixels'

Font size units, specified as the comma-separated pair consisting of 'FontUnits' and one of the following strings:

  • 'points'

  • 'normalized'

  • 'inches'

  • 'centimeters'

  • 'pixels'

When the value of FontUnits is 'normalized', MATLAB interprets the value of FontSize as a fraction of the height of the parent axes. When you resize the axes, MATLAB modifies the screen FontSize accordingly. points, inches, centimeters, and pixels are absolute units. 1 point = 1/72 inch

    Note:   When setting both the FontSize and the FontUnits, you must set the FontUnits property first so that MATLAB can correctly interpret the specified FontSize. For example, to set the font size to 0.3 inches, call 'FontUnits','inches','FontSize',0.3 in the argument list.

'FontWeight' — Weight of text characters'normal' (default) | 'bold' | 'light' | 'demi'

Weight of text characters, specified as the comma-separated pair consisting of 'FontWeight' and one of the following strings:

  • 'normal'

  • 'bold'

  • 'light'

  • 'demi'

MATLAB uses the FontWeight 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.

Example: 'FontWeight','bold'

'Interpreter' — Character interpretation'tex' (default) | 'latex' | 'none'

Character interpretation, specified as the comma-separated pair consisting of 'Interpreter' and one of the following strings.

Interpreter valueResult
'tex'Supports a subset of plain TeX markup language. See the String property for a list of supported TeX instructions.
'latex'Supports a basic subset of the LaTeX markup language.
'none'Interprets all characters as literal characters.

Example: 'Interpreter','latex'

Output Arguments

expand all

h — Handle to text objectscalar

Handle to the text object, returned as a scalar. This is a unique identifier, which you can use to query and modify the properties of the title.

See Also

| | | | | | |

Was this topic helpful?