Is it not possible to change every font size on plots at the same time?

92 views (last 30 days)
Is it not possible to change every font size on plots at the same time with only one command? (tics, legends, titles, axes, etc.)

Accepted Answer

Adam Danz
Adam Danz on 6 Jun 2018
Edited: Adam Danz on 18 Mar 2022
Update: Starting in MATLAB R2022a, use the fontsize function to scale font sizes and set font units in a figure. Release R2022a also includes the new fontname function to set font names within a figure. For a review, see this Community Highlight.
---------------------------------------------------------
From the file exchange, supersizeme(h, 1.5) increases the font size of all text in figure h (or axes h) by a factor of 1.5.
The function searches for all objects that have a fontsize property and scales the fontsizes. This preserves the relative difference in fontsizes between objects. It works with TeX interpreter text as well.
The images below are before and after increasing all fonts by x1.5 using supersizeme(1.5)

More Answers (6)

Walter Roberson
Walter Roberson on 6 Jun 2018
Edited: Walter Roberson on 28 Jan 2020
To change all text objects to have a particular font size, then
fig = gcf; %or one particular figure whose handle you already know, or 0 to affect all figures
set( findall(fig, '-property', 'fontsize'), 'fontsize', NewFontSize)
Note that this might not find the font size information on some of the more obscure graphics objects where it might be hidden some levels down. For example I would not assume that this code would be able to locate the font size information of the individual labels written into heatmap objects, or the font size information for contour labels created with clabel()
  12 Comments
Junho Kweon
Junho Kweon on 14 Mar 2021
@Walter Roberson Thank you for your sharing! It works greatly. By the way, when I want to set other elements with using your fontsize setting, how can I do it?
In other words, can I use these two lines into one 'set' function form?
set(gca,'FontWeight','bold','LineWidth',2)
set(findall(gcf,'-property','FontSize'),'FontSize',14)
Thanks,
Walter Roberson
Walter Roberson on 14 Mar 2021
set(findall(gcf,'-property','FontSize'),'FontSize',14, 'fontweight', 'bold', 'LineWidth', 2)
However it would be better to record the handles and specifically test them for having the other properties, in case there are objects that allow you to control some but not all of the properties.

Sign in to comment.


Tom Baldock
Tom Baldock on 12 Feb 2020
Combining a few threads which did not quite work, this seemed to work for me in R2019, placed at the end of a script, which modified all font size (axis names and numerical values, legens) on all open figures. You can then rerun these lines to get new sizes of any figure
fh = findall(0,'Type','Figure');
set( findall(fh, '-property', 'fontsize'), 'fontsize', 14)

Bruce Rodenborn
Bruce Rodenborn on 28 Jan 2020
This command, however, does change everything, at least in R2019a
a = get(gca,'XTickLabel');
set(gca,'XTickLabel',a,'fontsize',24)
though presumably this should only change the xticks.
MATLAB should make this all make sense - OY!
  4 Comments
Darcy
Darcy on 24 Mar 2022
Edited: Darcy on 24 Mar 2022
If I do:
figure(1)
title('Blah'); ylabel('Y'); xlabel('X')
set(gca,'FontSize',8)
a = get(gca,'XTickLabel');
set(gca,'XTickLabel',a,'fontsize',30)
It will make ALL the font on the figure to 30 point. Even though I set the fontsize to 8 earlier, the 'XTickLabel' seems to set the fonts for the whole figure even though, "presumably this should only change the xticks" as Bruce said.
This is really annoying because I am trying to change the font size of only the XTick labels.
Using MATLAB 2021a.
Walter Roberson
Walter Roberson on 24 Mar 2022
set(gca,'XTickLabel',a,'fontsize',30)
You should not understand this as setting the fontsize for only the XTickLabel. You should understand this command as the combination of commands
set(gca,'XTickLabel',a)
set(gca,'fontsize',30)
Options in a single set() call are independent of each other (though in a few cases, order can matter.)
What you should be doing instead is
set(a, 'fontsize', 30)

Sign in to comment.


dpb
dpb on 29 May 2015
Nope; they're individual properties of the various objects. You could do some building of some tools and/or link various properties together but there's no builtin function that does such globally, no.
You can, however, change the default properties for many things if that would help, to have plots be created more like you'd like initially.

Bruce Rodenborn
Bruce Rodenborn on 28 Jan 2020
None of these work. The command does not change labels or tickmarks or legends unless I am missing something. A MWE would be helpful.

Bruce Rodenborn
Bruce Rodenborn on 29 Jan 2020
Sorry for being a bit sloppy and thanks for the corrections. I got the previous command I posted from another thread, which was addressing only changing tick mark labels, but it changed all fonts (xlabel, ylabel, legend and tick marks to 24. Thus, I inadvertently found some lines that did what I want, but did not fully understand them. It seems that all I ever needed was the command:
set(gca,'fontsize',24),
which does set the defaul font size for the current axes. If issued before I label, I can change other text elements without affecting the default, e.g.:
set(gca,'fontsize',16),
ylabel('y')
xlabel('x')
legend('series 1','series 2', 'series 3','series 4','FontSize',24)
changes the font sizes of everything, but the legend is font size 24, which is as much control as I hoped.

Community Treasure Hunt

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

Start Hunting!