Legend text appearance and behavior
expand all in page
Legend text properties control the appearance and behavior of the legend title. By changing property values, you can modify certain aspects of the title. Use dot notation to refer to a particular object and property:
l = legend('show');l.Title.String = 'My Title';l.Title.Color = 'red';c = l.Title.Color
Text
expand all
String
— Text to display as title
character array | string array | cell array | categorical array | numeric value
Text to display as title, specified as a character array, string array, cell array, categorical array, or numeric value.
Example: 'my title'
Example: string('my title')
Example: {'first line','second line'}
Example: 123
To include numeric variables with text in a title, use the num2str function. For example:
x = 42;str = ['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.
To create multiline titles:
Use a string array, where each element contains a line of text, such as
string({'line one','line two'})
.Use a cell array where each cell contains a line of text, such as
{'first line','second line'}
.Use a character array where each row contains a line of text, such as
['abc'; 'ab ']
. If you use this technique, each row must contain the same number of characters.Use sprintf to create text with a new line character, such as
sprintf('first line \n second line')
.
Numeric titles are converted to text using sprintf('%g',value)
. For example, 12345678
displays as 1.23457e+07
.
Note
The words
default
,factory
, andremove
are reserved words that will not appear in a title when quoted as a normal character vector. To display any of these words individually, precede them with a backslash, such as'\default'
or'\remove'
.If you specify this property as a categorical array, MATLAB® uses the values in the array, not the categories.
InterpreterMode
— Selection mode for Interpreter
'auto'
(default) | 'manual'
Selection mode for the Interpreter
property, specified as one of these values:
'auto'
— Use the same value as theInterpreter
property for the associatedLegend
object.'manual'
— Use a value ofInterpreter
that you specify. To specify the value, set theInterpreter
property. When you set theInterpreter
property, theInterpreterMode
property changes to'manual'
.
Font Style and Appearance
expand all
ColorMode
— Selection mode for Color
'auto'
(default) | 'manual'
Selection mode for the Color
property, specified as one of these values:
'auto'
— Use the same value as theTextColor
property for the associatedLegend
object.'manual'
— Use a value ofColor
that you specify. To specify the value, set theColor
property. When you set theColor
property, theColorMode
property changes to'manual'
.
FontAngleMode
— Selection mode for FontAngle
'auto'
(default) | 'manual'
Selection mode for the FontAngle
property, specified as one of these values:
'auto'
— Use the same value as theFontAngle
property for the associatedLegend
object.'manual'
— Use a value ofFontAngle
that you specify. To specify the value, set theFontAngle
property. When you set theFontAngle
property, theFontAngleMode
property changes to'manual'
.
FontNameMode
— Selection mode for FontName
'auto'
(default) | 'manual'
Selection mode for the FontName
property, specified as one of these values:
'auto'
— Use the same value as theFontName
property for the associatedLegend
object.'manual'
— Use a value ofFontName
that you specify. To specify the value, set theFontName
property. When you set theFontName
property, theFontNameMode
property changes to'manual'
.
FontSizeMode
— Selection mode for FontSize
'auto'
(default) | 'manual'
Selection mode for the FontSize
property, specified as one of these values:
'auto'
— Use the same value as theFontSize
property for the associatedLegend
object.'manual'
— Use a value ofFontSize
that you specify. To specify the value, set theFontSize
property. When you set theFontSize
property, theFontSizeMode
property changes to'manual'
.
FontWeightMode
— Selection mode for FontWeight
'auto'
(default) | 'manual'
Selection mode for the FontWeight
property, specified as one of these values:
'auto'
— Use the same value as theFontWeight
property for the associatedLegend
object.'manual'
— Use a value ofFontWeight
that you specify. To specify the value, set theFontWeight
property. When you set theFontWeight
property, theFontWeightMode
property changes to'manual'
.
Version History
Introduced in R2016a
See Also
legend | title
MATLAB-Befehl
Sie haben auf einen Link geklickt, der diesem MATLAB-Befehl entspricht:
Führen Sie den Befehl durch Eingabe in das MATLAB-Befehlsfenster aus. Webbrowser unterstützen keine MATLAB-Befehle.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- Deutsch
- English
- Français
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本 (日本語)
- 한국 (한국어)
Contact your local office