How to change the font size of a plot's title and axis labels and save it?

人盡茶涼 提交于 2019-12-02 09:15:42

问题


Every time I save a plot picture as jpg or png, font size of title and axis label is changed back to default automatically. My code is like this:

figure
plot(x, f(x))
title('the smallest n = 1', 'FontSize', 24);
xlabel('x', 'FontSize', 24);
ylabel('x''', 'FontSize', 24);

After saving the picture, those font sizes become small again. Anyone knows why?


回答1:


Because it just applies for the current figure.

If you want to set the same font size for the whole session, use:

set(0,'defaultAxesFontSize', 12);

If you want that permanently, put it in your start-up file.


By the way, as you can see here you can build every "default property" you wish by concatenating default + class name + property.




回答2:


I found that "print" command can solve this problem.

fig = figure;
plot(x, f(x));
title('the smallest n = 1', 'FontSize', 24);
xlabel('x', 'FontSize', 24);
ylabel('x''', 'FontSize', 24);
print(fig, 'PicName', '-dpng');

The third argument is to specify the format. In my case, I would like to save it to png file.

The font size would remain the values I set now.




回答3:


Please try and use the following,

title(['\fontsize{16}black {\color{magenta}magenta '...
'\color[rgb]{0 .5 .5}teal \color{red}red} black again'])

It works for sure



来源:https://stackoverflow.com/questions/32655332/how-to-change-the-font-size-of-a-plots-title-and-axis-labels-and-save-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!