# Title matlab

## Add Title and Axis Labels to Chart

### Create Simple Line Plot

Create as 100 linearly spaced values between and . Create and as sine and cosine values of . Plot both sets of data.

x = linspace(-2*pi,2*pi,100); y1 = sin(x); y2 = cos(x); figure plot(x,y1,x,y2)

Add a title to the chart by using the function. To display the Greek symbol , use the TeX markup, .

title('Line Plot of Sine and Cosine Between -2\pi and 2\pi')

Add axis labels to the chart by using the and functions.

xlabel('-2\pi < x < 2\pi') ylabel('Sine and Cosine Values')

Add a legend to the graph that identifies each data set using the function. Specify the legend descriptions in the order that you plot the lines. Optionally, specify the legend location using one of the eight cardinal or intercardinal directions, in this case, .

legend({'y = sin(x)','y = cos(x)'},'Location','southwest')

### Change Font Size

objects have properties that you can use to customize the appearance of the axes. For example, the property controls the font size of the title, labels, and legend.

Access the current object using the function. Then use dot notation to set the property.

ax = gca; ax.FontSize = 13;

### Title with Variable Value

Include a variable value in the title text by using the function to convert the value to text. You can use a similar approach to add variable values to axis labels or legend entries.

Add a title with the value of .

k = sin(pi/2); title(['sin(\pi/2) = ' num2str(k)])

| | | |

## title

### Description

example

adds the specified title to the current axes or standalone visualization. Reissuing the command causes the new title to replace the old title.

example

modifies the title appearance using one or more name-value pair arguments. For example, sets the font size to 12 points. Specify name-value pair arguments after all other input arguments. Modifying the title appearance is not supported for all types of charts.

example

adds the title to the specified target object.

example

returns the object used for the title. Use to make future modifications to the title.

example

returns the objects used for the title and the subtitle. Use to modify the title, and use to modify the subtitle.

collapse all

### Add Title to Current Axes

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

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

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

MATLAB® sets the output of as the axes title.

### Create Title and Subtitle

Create a plot. Then create a title and a subtitle by calling the function with two character vectors as arguments. Use the name-value pair argument to customize the color for both lines of text. Specify two return arguments to store the text objects for the title and subtitle.

plot([0 1]) [t,s] = title('Straight Line','Slope = 1, y-Intercept = 0',...'Color','blue');

Change the font size for the title to , and change the font angle for the subtitle to .

t.FontSize = 16; s.FontAngle = 'italic';

### Include Variable's Value in Title

Include the value of variable 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

Use the color modifier to change the color of characters following it from the previous color.

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

### Create Title with LaTeX Markup

Create a plot, and define as a character vector that includes LaTeX markup. Surround the markup with dollar signs (). Then pass to the function, and set the property to .

x = 0:0.1:10; y = sin(x); dy = cos(x); plot(x,y,x,dy); t = '$sin(x)$ and $\frac{d}{dx}sin(x)$'; title(t,'interpreter','latex')

### Create Colored Title Using Name,Value Pair Argument

Use the pair 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 TeX markup 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 property must be (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 property as so that the text is displayed in the figure as typed, without making a subscript of .

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

### Add Title to Specific Axes

Starting in R2019b, you can display a tiling of plots using the and functions. Call the function to create a 2-by-1 tiled chart layout. Call the function to create the axes objects and . Then plot data into each axes.

tiledlayout(2,1) ax1 = nexttile; plot(ax1,(1:10).^2) ax2 = nexttile; plot(ax2,(1:10).^3)

Add a title to each axes by passing and to the function.

title(ax1,'Top Plot') title(ax2,'Bottom Plot')

### Add Title and Return Text Handle

Add a title to a plot and return the text object.

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

Set the color of the title to red. Use dot notation to set properties.

### Change Title Alignment

Create a plot with a title. Get the current axes, and then align the title to the left edge of the plot box by setting the property of the axes to .

plot([0 2],[1 5]) title('Straight Line') ax = gca; ax.TitleHorizontalAlignment = 'left';

Center the title setting the property on the axes to '.

ax.TitleHorizontalAlignment = 'center';

collapse all

### — Title text (default) | character vector | cell array of character vectors | string array | categorical array | numeric value

Title text, specified as a character vector, cell array of character vectors, string array, categorical array, or numeric value. Specify a value according to how you want the text to appear. This table lists the most common situations.

Appearance of TextDescription of ValueExample
One line of text Character vector or string scalar.or
Multiple lines of textCell array of character vectors or string array.
txt = {'First line','Second line'};
or
txt = ["First line", "Second line"];
Text that includes a numeric variableArray that includes the number converted to a array. Use to convert the value.
x = 42; txt = ['The value is ',num2str(x)];
Text that includes special characters such as Greek letters or mathematical symbolsArray that includes TeX markup. For a list of supported markup, see the property.
txt = 'x ranges from 0 to 2\pi'

Note

• The words , , and are reserved words that do not appear in text when quoted as normal characters. To display any of these words individually, precede them with a backslash, such as or .

• If you specify this property as a categorical array, MATLAB® uses the values in the array, not the categories.

• If you specify text that contains only a numeric value, the value is converted using . For example, displays as .

### — Subtitle text (default) | character vector | cell array of character vectors | string array | categorical array | numeric value

Subtitle text, specified as a character vector, cell array of character vectors, string array, categorical array, or numeric value. Specify a value according to how you want the text to appear. This table lists the most common situations.

Appearance of TextDescription of ValueExample
One line of text Character vector or string scalar.or
Multiple lines of textCell array of character vectors or string array.
txt = {'First line','Second line'};
or
txt = ["First line", "Second line"];
Text that includes a numeric variableArray that includes the number converted to a array. Use to convert the value.
x = 42; txt = ['The value is ',num2str(x)];
Text that includes special characters such as Greek letters or mathematical symbolsArray that includes TeX markup. For a list of supported markup, see the property.
txt = 'x ranges from 0 to 2\pi'

Note

• The words , , and are reserved words that do not appear in text when quoted as normal characters. To display any of these words individually, precede them with a backslash, such as or .

• If you specify this property as a categorical array, MATLAB uses the values in the array, not the categories.

• If you specify text that contains only a numeric value, the value is converted using . For example, displays as .

### — Target for titleaxes | legend | tiled chart layout | standalone visualization | array of objects

Target for the title, specified as one of the following:

• Any type of axes: an , , or object.

• Any type of legend: a or object.

• A object.

• A standalone visualization that has a property. For example, you can add a title to a object.

• An array of graphics objects from the preceding list. The objects must belong to the same class. To determine the class, use the function.

If you do not specify the target for the title, then the function adds the title to the graphics object returned by the command.

Note

Some charts do not support modifying the title appearance, such as the color, or returning the text object as an output argument.

### Name-Value Arguments

Specify optional comma-separated pairs of arguments. is the argument name and is the corresponding value. must appear inside quotes. You can specify several name and value pair arguments in any order as .

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

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

### — Font size (default) | scalar value greater than 0

Font size, specified as a scalar value greater than in point units. One point equals 1/72 inch. To change the font units, use the property.

If you add a title or subtitle to an axes object, then the font size property for the axes also affects the font size for the title and subtitle. The title and subtitle font sizes are the axes font size multiplied by a scale factor. The property of the axes contains the axes font size. The property of the axes contains the scale factor. By default, the axes font size is 10 points and the scale factor is 1.1, so the title and subtitle each have a font size of 11 points.

Data Types: | | | | | | | | |

### — Thickness of text characters |

Thickness of the text characters, specified as one of these values:

• — Normal weight as defined by the particular font

• — Thicker characters outlines than normal

MATLAB uses the property to select a font from those available on your system. Not all fonts have a bold font weight. Therefore, specifying a bold font weight could still result in the normal font weight.

The property for the associated axes affects the value for the title. Similarly, the property for the associated axes affects the value for the subtitle.

Note

The and font weight values have been removed. Use instead.

### — Font namesupported font name |

Font name, specified as a supported font name or . 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 . The fixed-width font relies on the root property. Setting the root property causes an immediate update of the display to use the new font.

### — Text color (default) | RGB triplet | hexadecimal color code | | | | ...

Text color, specified as an RGB triplet, a hexadecimal color code, a color name, or a short name. The default value of corresponds to black.

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

• An RGB triplet is a three-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 ; for example, .

• A hexadecimal color code is a character vector or a string scalar that starts with a hash symbol () followed by three or six hexadecimal digits, which can range from to . The values are not case sensitive. Thus, the color codes , , , and are equivalent.

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

Color NameShort NameRGB TripletHexadecimal Color CodeAppearance
Not applicableNot applicableNot applicableNo color

Here are the RGB triplets and hexadecimal color codes for the default colors MATLAB uses in many types of plots.

Example:

Example:

Example:

### — Text interpreter (default) | |

Text interpreter, specified as one of these values:

• — Interpret characters using a subset of TeX markup.

• — Interpret characters using LaTeX markup.

• — Display literal characters.

#### TeX Markup

By default, MATLAB supports a subset of TeX markup. Use TeX markup to add superscripts and subscripts, modify the font type and color, and include special characters in the text.

Modifiers remain in effect until the end of the text. Superscripts and subscripts are an exception because they modify only the next character or the characters within the curly braces. When you set the interpreter to , the supported modifiers are as follows.

ModifierDescriptionExample
Superscript
Subscript
Bold font
Italic font
Oblique font (usually the same as italic font)
Normal font
Font name — Replace with the name of a font family. You can use this in combination with other modifiers.
Font size —Replace with a numeric scalar value in point units.
Font color — Replace with one of these colors: , , , , , , , , , , or .
Custom font color — Replace with a three-element RGB triplet.

This table lists the supported special characters for the interpreter.

Character SequenceSymbolCharacter SequenceSymbolCharacter SequenceSymbol

α

υ

~

χ

β

ψ

γ

ω

δ

Γ

ϵ

Δ

ζ

Θ

η

Λ

θ

Ξ

ϑ

Π

ι

Σ

κ

ϒ

λ

Φ

µ

Ψ

º

ν

Ω

±

ξ

π

ρ

σ

ς

÷

τ

·

ο

¬

x

...

´

ϖ

|

#### LaTeX Markup

To use LaTeX markup, set the interpreter to . For inline mode, surround the markup with single dollar signs (). For display mode, surround the markup with double dollar signs ().

LaTeX ModeExampleResult
Inline
Display

The displayed text uses the default LaTeX font style. The , , and properties do not have an effect. To change the font style, use LaTeX markup.

The maximum size of the text that you can use with the LaTeX interpreter is 1200 characters. For multiline text, this reduces by about 10 characters per line.

For examples that use TeX and LaTeX, see Greek Letters and Special Characters in Chart Text. For more information about the LaTeX system, see The LaTeX Project website at https://www.latex-project.org/.

collapse all

### — Object used for titletext object | legend text object

Object used for the title, returned as one of these types of objects:

• Text object — If you add a title to axes, then returns a text object. Use this text object to access and modify properties of the title after it is created. For a list of text object properties, see Text Properties. You also can access the title through the property of the axes object.

• Legend text object — If you add a title to a legend, then returns a legend text object. Use this legend text object to access and modify properties of the title after it is created. For a list of legend text object properties, see Text Properties. You also can access the title through the property of the legend object.

### — Object used for subtitletext object

Object used for the subtitle, returned as a text object. Use this text object to modify properties of the subtitle after creating it. For a list of text object properties, see Text Properties. You also can access the subtitle through the property of the axes object.

### Tips

• By default, the property contains so the text can be edited by clicking on the text. To disable this interaction, set the property of the text object to .

### Properties

Introduced before R2006a

You have a modified version of this example. Do you want to open this example with your edits?

You clicked a link that corresponds to this MATLAB command:

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

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: .

Select web site

You can also select a web site from the following list:

### How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

Sours: https://www.mathworks.com/help/matlab/ref/title.html

## Select a Web Site

### Make the Graph Title Smaller

MATLAB® graphics titles use a bold and slightly larger font for better visibility. As a result, some text might not fit within the extents of the figure window. For example, this code creates a graph that has a long title that does not fit within the extents of the figure window.

plot(1:10); title(['This is a title that is too long and does not fit',...'within the extents of the figure window.'])

The title font size is based on the and properties of the axes. By default the property is 10 points and the is , which means that the title font size is 11 points.

To change the title font size without affecting the rest of the font in the axes, set the property of the axes.

plot(1:10); title(['This is a title that is too long and does not fit',...'within the extents of the figure window.']) ax = gca; ax.TitleFontSizeMultiplier = 1;

To make the font size smaller for the entire axes, set the property. Changing this property affects the font for the title, tick labels and axis labels, if they exist.

plot(1:10); title(['This is a title that is too long and does not fit',...'within the extents of the figure window.']) ax = gca; ax.FontSize = 8;

To keep the same font size and display the title across two lines, use a cell array with curly brackets to define a multiline title.

plot(1:10); title({'This is a title that is too long and does not fit',...'within the extents of the figure window.'})

### Properties

Sours: https://www.mathworks.com/help/matlab/creating_plots/how-do-i-make-the-graph-title-smaller.html
 MATLAB Function Reference
title

Syntax

• title('') title(fname) title(...,'',PropertyValue,...) h = title(...)

Description

Each axes graphics object can have one title. The title is located at the top and in the center of the axes.

outputs the string at the top and in the center of the current axes.

evaluates the function that returns a string and displays the string at the top and in the center of the current axes.

specifies property name and property value pairs for the text graphics object that creates.

returns the handle to the text object used as the title.

Examples

Display today's date in the current axes:

Include a variable's value in a title:

• f = 70; c = (f--32)/1.8; title(['Temperature is ',num2str(c),'C'])

Include a variable's value in a title and set the color of the title to yellow:

• n = 3; title(['Case number #',int2str(n)],'Color','y')

Include Greek symbols in a title:

• title('\ite^{\omega\tau} = cos(\omega\tau) + isin(\omega\tau)')

Include a superscript character in a title:

Include a subscript character in a title:

The text object property lists the available symbols.

Remarks

sets the property of the current axes graphics object to a new text graphics object. See the text property for more information.

, , , , , ,

Annotating Plots for related functions

 timerfind toeplitz

Sours: http://www.ece.northwestern.edu/local-apps/matlabhelp/techdoc/ref/title.html

## Matlab title

 MATLAB Function Reference
title

Syntax

• title('') title(fname) title(...,'',PropertyValue,...) title(axes_handle,...) h = title(...)

Description

Each axes graphics object can have one title. The title is located at the top and in the center of the axes.

outputs the string at the top and in the center of the current axes.

evaluates the function that returns a string and displays the string at the top and in the center of the current axes.

specifies property name and property value pairs for the text graphics object that creates.

adds the title to the specified axes.

returns the handle to the text object used as the title.

Examples

Display today's date in the current axes:

Include a variable's value in a title:

• f = 70; c = (f--32)/1.8; title(['Temperature is ',num2str(c),'C'])

Include a variable's value in a title and set the color of the title to yellow:

• n = 3; title(['Case number #',int2str(n)],'Color','y')

Include Greek symbols in a title:

• title('\ite^{\omega\tau} = cos(\omega\tau) + isin(\omega\tau)')

Include a superscript character in a title:

Include a subscript character in a title:

The text object property lists the available symbols.

Create a multiline title using a multiline cell array.

• title({'First line';'Second line'})

Remarks

sets the property of the current axes graphics object to a new text graphics object. See the text property for more information.

, , , , , ,

Annotating Plots for related functions

 timerfindall todatenum

Sours: http://matlab.izmiran.ru/help/techdoc/ref/title.html

.

### You will also like:

.

395 396 397 398 399