Is it not possible to change every font size on plots at the same time?
68 次查看(过去 30 天)
显示 更早的评论
Is it not possible to change every font size on plots at the same time with only one command? (tics, legends, titles, axes, etc.)
0 个评论
采纳的回答
Adam Danz
2018-6-6
编辑:Adam Danz
2022-3-18
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)
0 个评论
更多回答(6 个)
Walter Roberson
2018-6-6
编辑:Walter Roberson
2020-1-28
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 个评论
Junho Kweon
2021-3-14
@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
2021-3-14
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.
Tom Baldock
2020-2-12
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)
0 个评论
Bruce Rodenborn
2020-1-28
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 个评论
Darcy
2022-3-24
编辑:Darcy
2022-3-24
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
2022-3-24
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)
dpb
2015-5-29
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.
0 个评论
Bruce Rodenborn
2020-1-28
None of these work. The command does not change labels or tickmarks or legends unless I am missing something. A MWE would be helpful.
2 个评论
Adam Danz
2020-1-28
The function I recommended does work, even if you've used TeX markup (but not if you've used Latex).
Bruce Rodenborn
2020-1-29
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Labels and Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!