This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

sgtitle

Add title to subplot grid

Syntax

sgtitle(txt)
sgtitle(target,txt)
sgtitle(___,Name,Value)
sgt = sgtitle(___)

Description

example

sgtitle(txt) adds a title above the grid of subplots in the current figure. If a figure does not it exist, then this command creates one.

sgtitle(target,txt) adds the title to the subplot grid in the specified figure, panel, or tab, instead of the current figure.

sgtitle(___,Name,Value) modifies text properties using one or more name-value pair arguments. For example, 'FontSize',12 specifies 12-point font. For a list of properties, see Text Properties. Specify name-value pair arguments after all the other input arguments.

sgt = sgtitle(___) returns the subplot Text object used to create the title.

Examples

collapse all

Create a figure with four subplots. Add a title to each subplot, and then add an overall title to the subplot grid.

subplot(2,2,1)
title('First Subplot')
subplot(2,2,2)
title('Second Subplot')
subplot(2,2,3)
title('Third Subplot')
subplot(2,2,4)
title('Fourth Subplot')

sgtitle('Subplot Grid Title')

Modify a title appearance by setting properties, first by using name-value pair arguments, and then by returning the Text object created and using dot notation.

Change the Color property using a name-value pair argument. Next, change the FontSize property using dot notation.

subplot(2,1,1)
title('First Subplot')
subplot(2,1,2)
title('Second Subplot')

sgt = sgtitle('Subplot Grid Title','Color','red');
sgt.FontSize = 20;

Input Arguments

collapse all

Text to display, specified as a character vector, cell array of character vectors, string array, or numeric value.

Example: 'my label'

Example: {'first line','second line'}

Example: string('my label')

Example: 123

To include numeric variables with text, use the num2str function. For example:

x = 42;
txt = ['The value is ',num2str(x)];

To include special characters, such as superscripts, subscripts, Greek letters, or mathematical symbols use TeX markup. For a list of supported markup, see the Interpreter property of the Text object.

To create multiline text, use these conventions:

  • Use a cell array, where each cell contains a line of text, such as {'first line','second line'}.

  • Use a string array, where each element contains a line of text, such as string({'line one','line two'}).

  • Use a character array, where each row contains the same number of characters, such as ['abc'; 'ab '].

  • Use sprintf to create text with a new line character, such as sprintf('first line \n second line'). This property converts text with new line characters to cell arrays.

If the text contains only a numeric value, then it is converted using sprintf('%g',value). For example, 12345678 displays as 1.23457e+07.

Subplot grid container, specified as a Figure, Panel, or Tab object.

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 quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: sgtitle('My Title','FontSize',14)

Note

The properties listed here are only a subset. For a full list, see Text Properties.

Font size, specified as a scalar value greater than zero in point units. The default font size depends on the specific operating system and locale. One point equals 1/72 inch. To change the font units, use the FontUnits property.

Example: 12

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

Font name, specified as a supported font name or 'FixedWidth'. To display and print text properly, you must choose a font that your system supports. The default font depends on your operating system and locale.

To use a fixed-width font that looks good in any locale, use 'FixedWidth'. The fixed-width font relies on the root FixedWidthFontName property. Setting the root FixedWidthFontName property causes an immediate update of the display to use the new font.

See Also

Functions

Properties

Introduced in R2018b