1,418 views (last 30 days)
Show older comments
Hassan on 15 Jun 2011
-
-
Link
Direct link to this question
https://www.mathworks.com/matlabcentral/answers/9559-how-can-i-change-the-font-size-of-the-current-axis
Answered: Sulaymon Eshkabilov on 20 Jan 2023
Accepted Answer: Matt Fig
Open in MATLAB Online
How can I change the font size of the axes of the current graph without creating new axes? For example, if we have this plot already, how can I change the font size?
x = rand(10,10);
y = rand(10,10);
plot(x,y)
0 Comments Show -2 older commentsHide -2 older comments
Show -2 older commentsHide -2 older comments
Sign in to comment.
Sign in to answer this question.
Accepted Answer
Matt Fig on 28 Apr 2022
Edited: MathWorks Support Team on 28 Apr 2022
Open in MATLAB Online
To change the font size, set the FontSize property on the axes object after plotting. For example:
x = rand(10,10);
y = rand(10,10);
plot(x,y);
set(gca,”FontSize”,20)
Starting in R2022a, you can use the “fontsize” function to change the font size for any graphics object that has text associated with it. In this case, pass the axes object to the “fontsize” function followed by the desired font size in points. For example:
fontsize(gca,20)
You can also change the font name using the “fontname” function. The font you specify must be installed on your system. For example, change the font of the current axes to Courier:
fontname(gca,"Courier")
3 Comments Show 1 older commentHide 1 older comment
Show 1 older commentHide 1 older comment
Hassan on 15 Jun 2011
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/9559-how-can-i-change-the-font-size-of-the-current-axis#comment_20876
thanks a lot Matt.
Luis Humberto Niño Alvarez on 17 Sep 2019
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/9559-how-can-i-change-the-font-size-of-the-current-axis#comment_746897
Thanks Matt
Viktor Erdelyi on 16 May 2022
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/9559-how-can-i-change-the-font-size-of-the-current-axis#comment_2160400
On my end, I had to specify the fontsize unit as shown here.
Sign in to comment.
More Answers (2)
Image Analyst on 16 May 2022
- axes_colors.m
See attached demo to see how you can independently change a wide variety of things in your axes.
3 Comments Show 1 older commentHide 1 older comment
Show 1 older commentHide 1 older comment
Rhythm Analyst on 26 Oct 2022
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/9559-how-can-i-change-the-font-size-of-the-current-axis#comment_2431853
Edited: Rhythm Analyst on 26 Oct 2022
Image Analyst, your file is really helpful.
However, I cannot get it to work when I split y axis into a left and right axis...
The left axis worked fine, only because I did not specify "yyaxis left" before line 54.
Only at line 58 did I introduce having two y axes. I do not know how to use comma-separated list assignments to accomplish changing the font size of the values on the right y axis.
Any help would be appreciated, thank you.
Image Analyst on 26 Oct 2022
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/9559-how-can-i-change-the-font-size-of-the-current-axis#comment_2431893
Attach your script and say what you want each y axis to look like (fontsize, color, tickmarks, or whatever).
Rhythm Analyst on 26 Oct 2022
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/9559-how-can-i-change-the-font-size-of-the-current-axis#comment_2432068
- lab3.m
Solved the issue; I was using ax=gca; for both 'yyaxis left' and 'yyaxis right'. Fix was to have ax1 for left yaxis and ax2 for right yaxis; as far as I can tell thats what fixed it anyway...
Thanks for the response.
Sign in to comment.
Sulaymon Eshkabilov on 20 Jan 2023
Open in MATLAB Online
There is one minor correction with one of the otptions proposed by @Mat Fig using fontsize() the unit has to be specified:
x = 1:5;
y = randi(5,1,5);
plot(x,y)
fontsize(gca, 15,'points') % 'pixels', 'centimeters', 'inches'
0 Comments Show -2 older commentsHide -2 older comments
Show -2 older commentsHide -2 older comments
Sign in to comment.
Sign in to answer this question.
See Also
Categories
MATLABGraphicsFormatting and AnnotationLabels and AnnotationsAnnotations
Find more on Annotations in Help Center and File Exchange
Tags
- customize axes appearance
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
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)
- 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)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)
Contact your local office