MATLAB Answers

How do I change the font size for text in my figure?

8,907 ビュー (過去 30 日間)
Edward
Edward 2014 年 5 月 26 日
コメント済み: Image Analyst 2020 年 2 月 11 日
I'm using "set(gca,'fontsize', 18);" in a function to change fonts in a figure. My code does not throw an error, but it also does not change the font size. I can manually change the fonts via the UI, but this is a slow process. I'm running MATLAB 2013a on RHEL6.5
I've also tried "set(gca,'FontSize', 18);" and specifying 'FontSize', 18 in title, xlabel, ylabel and legend. None of these have worked.
Please advise!

  7 件のコメント

表示 4 件の古いコメント
Carry
Carry 2016 年 3 月 23 日
If you set axis properties in your figure (XLim, YLim etc) you have to give the command referring to the fontsize at the end. So first the plot command then axis properties and then ylabel with fontsize. Maybe there's another way but this did it for me.
hassan  roohian
hassan roohian 2016 年 10 月 7 日
>> help xlabel...
xlabel('text','property1',property1value,'property2',property2value)
here is an example...
title('speed vs. time','fontsize',18);
you can include more properties inside the parenthesis, i only did one in my example
Ian Hunter
Ian Hunter 2017 年 9 月 19 日
Edward's sol worked for me on ubuntu w/ R2016A many thx!

サインイン to comment.

採用された回答

Image Analyst
Image Analyst 2014 年 5 月 27 日
Usually you can set the font size on every control individually as you update its text, like
title('This is my plot', 'FontSize', 24);
xlabel('x axis', 'FontSize', 24);
text(x, y, 'Hey, look at this', 'FontSize', 24);
What's wrong with doing it like that? That's what I do.

  5 件のコメント

表示 2 件の古いコメント
Edward
Edward 2014 年 5 月 29 日
Here's the screen shot, as requested...
Image Analyst
Image Analyst 2014 年 5 月 29 日
I don't know. That's bizarre. You should call tech support.
Peter
Peter 2016 年 9 月 27 日
well, probably this font is not available in other sizes

サインイン to comment.

その他の回答 (6 件)

Mike Garrity
Mike Garrity 2016 年 2 月 10 日
Yes, this can be confusing. Here's what you're probably seeing:
figure % Creates a figure
set(gca,'FontSize',18) % Creates an axes and sets its FontSize to 18
plot(x,y) % Resets the axes and plots into it
Notice the "Resets the axes" part. One of the things that happens there is that the FontSize property gets set to the default!
This doesn't happen when hold is on because then the axes doesn't get reset.
There are a couple of ways around this.
The simplest is to set the FontSize after plotting.
A somewhat more complicated way is to change the default:
figure('DefaultAxesFontSize',18)
plot(x,y)
Does that make sense?

  1 件のコメント

Rik
Rik 2017 年 2 月 9 日
The point is that the font size property is inherited from the figure. So instead of calling gca, you should call gcf. But indeed, best practice is setting the font size on creation of the figure window.

サインイン to comment.


José Crespo Barrios
José Crespo Barrios 2016 年 2 月 10 日
set(findall(gcf,'-property','FontSize'),'FontSize',18)

  3 件のコメント

Ian Hunter
Ian Hunter 2017 年 9 月 19 日
When I invoke this after a call to figure, there does not appear to be any change in text size.
Ian Hunter
Ian Hunter 2017 年 9 月 19 日
on ubuntu w/ R2016A
ubaid haroon
ubaid haroon 2019 年 6 月 27 日
I use this on unix R2015a and it seems to work for me

サインイン to comment.


Sean de Wolski
Sean de Wolski 2014 年 5 月 27 日
I think what you want to do is set the 'Default' font size for the axes
set(gca,'DefaultTextFontSize',18)
Now any text object on that axes will have 18 font
text(0.5,0.5,'hello')

  3 件のコメント

Image Analyst
Image Analyst 2014 年 5 月 29 日
Edward's "Answer" moved here since it's a reply to Sean:
set(gca,'DefaultTextFontSize',18) executes without triggering an error, but unfortunately, does not change the font size.
vvf vvff
vvf vvff 2020 年 2 月 10 日
This command is awoseme!!!!!!!!!!!!
Image Analyst
Image Analyst 2020 年 2 月 11 日
Or, since r2014b, you can do it without the set() function:
ax = gca;
ax.DefaultTextFontSize = 18;

サインイン to comment.


Renato Campana
Renato Campana 2017 年 11 月 18 日
Im working with Matlab 2016. You can tried two things:
1)figure('DefaultAxesFontSize',30); % here the font size is 30. figure (1) plot(x,y,'LineWidth',4); % note that the linewidth here is 4 xlabel('length bar','FontSize',18); % note that the font size label here is 18 ylabel('wide bar','FontSize',18); % note that the font size label here is 18
and you must to use the dame command figure('DefaultAxesFontSize',30) in each figure. If you dont specified the font size in each label, the labels shows the size in "30"
Or you can tried:
2) figure (1) plot(x,y,'LineWidth',4); set(gca,'FontSize',28); % please, note that the font size is AFTER the plot command :)

  0 件のコメント

サインイン to comment.


Anu
Anu 2015 年 1 月 1 日
I have also encountered the same problem. I was using Linux Mint OS. I solved it by installing the xfont 100 and 75 dpi and the truetype fonts. Try it out once.

  0 件のコメント

サインイン to comment.


Daniel
Daniel 2015 年 3 月 26 日
I just wanted to weigh in on this given I've spent the last couple of hours looking into this.
I am running Matlab 2013b on Ubuntu 12.04LTS. Similar as many here, changing labels/legend properties works fine but setting the axis ticklabel fontname/size was not working - at least, the axis property list reflected the change, but the window plot was not rendering to the new font settings. After printing the plot to eps and including this in my latex compiled document, it turns out the axis font properties were changing. It would appear to be just a rendering bug.
Installing additional fonts did not work for me - and I did not expect to, since rendering/changing font properties of other objects such as labels and legends worked fine in Matlab.
So for those of you cocnerned with the looks of your plots for publications, it would appear to me that the actual exported figures do reflect the editing (at least this was my experience when printing to .eps).
Cheers,
Daniel

  0 件のコメント

サインイン to comment.

サインイン してこの質問に回答します。


Translated by