2014-02-11 28 views
3

有沒有辦法改變MATLAB中x軸的字體大小屬性的數字?我需要更改x軸中值的大小(不是標題,可以用xlabel屬性修改)。我有下一段代碼:如何更改x軸的字體大小?

%% 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軸。

+0

你試圖改變軸上刻度標籤的大小?你的代碼比這更復雜... – jvriesem

回答

9

我總是做下列方式:

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

這樣,軸和標籤將有所需的字體和大小。在'set'之後放置'xlabel''ylabel'是很重要的。這種情況下的順序很重要。

還有其他的方式來設置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); 
+0

真棒。僅供參考:與其他解決方案不同,此方法適用於semilog和loglog圖。我猜想它一般工作。 – jvriesem