Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matlab 如何更改x轴的字体大小?_Matlab_Axis_Figure - Fatal编程技术网

Matlab 如何更改x轴的字体大小?

Matlab 如何更改x轴的字体大小?,matlab,axis,figure,Matlab,Axis,Figure,有没有办法在MATLAB中更改图形x轴的字体大小属性?我需要更改x轴中值的大小(不是标题,可以使用xlabel属性修改标题)。我有下一段代码: %% 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', [p

有没有办法在MATLAB中更改图形x轴的字体大小属性?我需要更改x轴中值的大小(不是标题,可以使用
xlabel
属性修改标题)。我有下一段代码:

%% 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轴即可。

我始终按以下方式执行:

plot(X)
set(gca, 'FontName', 'Arial')
set(gca, 'FontSize', 12)
ylabel('Label Y axis')
xlabel('Label X axis')
这样,轴和标签将具有所需的字体和大小。将
'xlabel'
'ylabel'
放在
'set'
之后很重要。在这种情况下,命令很重要

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

% 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);

是否尝试更改轴上记号标签的大小?你的代码比这要复杂得多…太棒了。仅供参考:与其他一些解决方案不同,此方法适用于半对数和对数图。我想它一般都能用。