How do I change the font size of text in a figure?

조회 수: 186 (최근 30일)
MathWorks Support Team
MathWorks Support Team 2020년 2월 27일
편집: MathWorks Support Team 2024년 5월 21일
I want to change the font size for the title, axis labels, and other text in my figure. How do I do this?

채택된 답변

MathWorks Support Team
MathWorks Support Team 2024년 5월 14일
편집: MathWorks Support Team 2024년 5월 21일
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.  
plot(1:10)
title('My title')
xlabel('My label')
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.
plot(1:10)
title('My title','FontSize',16)
xlabel('My label','FontSize',10) 
MATLAB R2022a and later versions:
Starting in MATLAB R2022a, to scale font sizes and set font units in a figure, use the "fontsize" function:
Using the "fontsize" 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" function that sets font names within a figure:
For a review of these features, see the following Community Highlight:

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Labels and Annotations에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

제품


릴리스

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by