|On this page…|
In a MATLAB® figure, a title is a text string at the top of an axes. It appears in the figure border, not within the axes it describes. Titles typically define the subject of the graph. The following figure shows a title, centered at its top.
Note While you can use text annotations to create a title for your graph, it is not recommended. Titles are anchored to the top of the axes they describe; text annotations are not. If you move or resize your axes, the title remains at the top. Additionally, if you cut a title and then paste it back into a figure, the title is no longer anchored to the axes.
You can add a title to a graph in several ways, described in the following sections.
To add a title to a graph using the Insert menu,
When you are finished entering text, click anywhere in the figure background to close the text entry box around the title. If you click on another object in the figure, such as an axes or line, you close the title text entry box and also automatically select the object you clicked.
To change the font used in the title to bold, you must edit the title. You can edit the title as you would any other text object in a graph.
To add a title to a graph using the Property Editor,
Double-click an empty region of the axes in the graph. This starts the Property Editor. You can also start the Property Editor by right-clicking on the axes and selecting Show Property Editor from the context menu or by selecting Property Editor from the View menu.
The Property Editor displays a property panel specific to axes objects. Titles are a property of axes objects.
You can change the font, font style, position, and many other aspects of the title format.
To move the title, select the text and drag it to the desired position.
To edit the text, double-click the title and type new characters.
To change the font and other text properties, select the title and right-click to display the context menu.
To add a title to a graph at the MATLAB command prompt or from a file, use the title function.
For example, the following code adds a title to the current axes and sets the value of the FontWeight property to bold.
title('Lotka-Volterra Predator-Prey Population Model',... 'FontWeight','bold')
The following figure shows a plot with this title. It also contains a legend and text objects.
Titles are associated with axes. This means that when you make subplots, each axes can have a distinct title. If you create a title in this way when no figures exist, a blank figure with an axes is generated displaying the title you specified.
To edit a title from the MATLAB command prompt or from a file, use the set function with the title's handle, as follows:
title_handle = title('This is the original title'); set(title_handle,'String','This is a revised title')
You can also change title strings in plot edit mode or with the Property Inspector. For more information, including code that generates the figure shown here, see the example in Creating Text with the text or gtext Function.