How do I change the font size of text in a figure?
2,944 views (last 30 days)
MathWorks Support Team on 28 Mar 2022
Edited: MathWorks Support Team on 28 Mar 2022
MATLAB R2021b and earlier versions:
To change the font size, set the “FontSize” property for the axes. Since many plotting functions reset axes properties, including the font size, set the "FontSize" property after plotting.
For example, the code below sets the font size to 16 points. The tick labels use the specified font size. The title and axis labels use a slightly larger font size.
ax = gca;
ax.FontSize = 16;
Alternatively, if you want more individual control over the font size, you can specify the “FontSize” property as name-value pair to the “title” and “xlabel” functions, as in the example below.
MATLAB R2022a and later versions:
Starting in MATLAB R2022a, to scale font sizes and set font units in a figure, use the "fontsize" MATLAB function:
Using the "fontsize" MATLAB function you can set the font size for all objects in a figure or incrementally increase/decrease font size while maintaining relative differences.
MATLAB R2022a also includes the new "fontname" MATLAB function that sets font names within a figure:
For a review, see the following Community Highlight: