如何更改X轴的字体大小? [英] How to change font size of x axis?

查看:172
本文介绍了如何更改X轴的字体大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以更改图形中MATLAB的x轴的字体大小属性吗?我需要更改x轴上的值的大小(而不是标题,可以使用xlabel属性进行修改).我有下一段代码:

Is there any way to change the font size property of x axis in MATLAB for a figure? I need to change the size of the values in x axis (not the title, that one could modify with xlabel property). I have the next piece of code:

%% Some figure properties:
width=15;height=20;alw=0.75;

%% Figure:
for i=1:8
      figure;set(gcf,'color','white');
      pos=get(gcf, 'Position');
      set(gcf, 'Position', [pos(1) pos(2) width*100, height*100]);
      set(gca, 'LineWidth', alw);axis off;
      axes('position',[0.06 0.08 0.87 0.38])
      plot(0:24,s(i).obs(:,1),'linewidth',2,'color','b');hold on;
      plot(0:24,s(i).sim(:,1)-273.15,'linewidth',2,'color','r');
      legend('Obs','Sim','location','northeastoutside');
      set(gca,'xtick',0:24,'xticklabel',0:24);
      set(gca,'ytick',2:2:28,'yticklabel',2:2:28);
      xlabel('Hour');ylabel('[°C]');axis([0 24 2 28]);grid on;
      axes('position',[0.06 0.53 0.87 0.38]);
      plot(s(i).time.obs,s(i).serie.obs,'b');hold on;
      plot(s(i).time.sim,s(i).serie.sim-273.15,'r');
      datetick('x','myy');axis tight;grid on;
      legend('Obs','Sim','location','northeastoutside');
      title([s(i).name ', porcNaN: ' num2str(roundn(s(i).rnan,-1)) ...
          '%, period: '  datestr(s(i).period(1,:),20) ' - '...
           datestr(s(i).period(2,:),20)],'fontsize',12);
      ylabel('[°C]');set(gca,'fontsize',8)
      image_name=['temp_sup_' s(i).name];
      print(image_name,'-dpng','-r600')
end

"s"是一个结构.问题是第二个绘图(上图)的x轴中的值,datetick放置了所有月份和年份的值,我需要此信息(每个月),但它们之间的距离非常近.我知道"fontsize"属性,但是此属性会更改两个轴(x和y)上的字体大小,而我只需要更改x轴即可.

"s" is a struct. The problem is the values in the x axis of the second plot (the figure above), datetick put all months and years values, I need this information (each one month), but they're very close together. I know the "fontsize" property, but this property change the font size in the two axis (x and y), and I need only change the x axis.

推荐答案

我总是按照以下方式进行操作:

I always do it in the following way:

plot(X)
set(gca, 'FontName', 'Arial')
set(gca, 'FontSize', 12)
ylabel('Label Y axis')
xlabel('Label X axis')

通过这种方式,轴和标签将具有所需的字体和大小.重要的是将'xlabel''ylabel'放在'set'之后.在这种情况下,顺序很重要.

In this way, the axis and the label will have the requested font and size. It is important to put 'xlabel' and 'ylabel' after the 'set'. The order in this case matters.

还有另一种设置xlabel,ylable,legend,plot字体的方法,如下所示;它可以补充上面的答案:

There is other way to set the fonts for the xlabel, ylable, legend, plot as below; it may complement the upper answer:

% Define values
linewidthnumber = 2;
legendfontsize = 12;
labelfontsize = 12;
axisfontsize = 12;
custom_plot_handle_name = plot(x);
custom_legend_handle_name = legend();
custom_x_label_name = xlabel();
custom_y_label_name = ylabel();

% Set the parameters now to the given values
set(h, 'Linewidth', linewidthnumber);
set(custom_legen_handle_name,'FontSize', legendfontsize);
set(custom_x_label_name, 'FontSize', labelfontsize);
set(custom_y_label_name, 'FontSize', labelfontsize);
set(gca, 'FontSize', axisfontsize);

这篇关于如何更改X轴的字体大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆