2013-05-06 105 views
1

下面的代碼片段僅將較大的字體大小應用於底部繪圖,而不是頂部繪圖。如何將相同的設置應用於每個圖的每個子圖?

subplot(2,1,1) 
pcolor(lon(Lon2Use),-dep,v(Lon2Use,:)'); shading('flat'); colorbar 
subplot(2,1,2) 
pcolor(lon(Lon2Use),-dep,PressureGeo(Lon2Use,:)'); shading('flat'); colorbar 
set(gca,'FontSize',20) 
title('v along constant latitude line') 
xlabel('longitude') 
ylabel('depth') 

我怎樣才能做到頂部情節,最好是儘可能少的額外步驟?

回答

2

你有幾個選項。由於功能gca總是返回具有當前焦點軸的手柄,最簡單的方法是簡單地使每個小區後重覆命令:

subplot(2,1,1) 
pcolor(lon(Lon2Use),-dep,v(Lon2Use,:)');shading('flat');colorbar 
set(gca,'FontSize',20) %<----First axis has focus at this point 
subplot(2,1,2) 
pcolor(lon(Lon2Use),-dep,PressureGeo(Lon2Use,:)');shading('flat');colorbar 
set(gca,'FontSize',20) %<----Second axis has focus at this point 

或者,如果你希望所有的軸總是有默認字體大小,您可以set the default sizeroot object像這樣運行的所有上面的代碼之前:

set(0, 'DefaultAxesFontSize', 20); 

而且你的軸將自動有字體大小。

1

這裏有幾個選項。您既可以只重複調用您所創建的第二軸,即前,

subplot(2,1,1) 
pcolor(lon(Lon2Use),-dep,v(Lon2Use,:)');shading('flat');colorbar 
set(gca,'FontSize',20) 
subplot(2,1,2) 
pcolor(lon(Lon2Use),-dep,PressureGeo(Lon2Use,:)');shading('flat');colorbar 
set(gca,'FontSize',20) 

或者,你可以在返回值從subplot存儲(軸手柄),並設置這些屬性,即

ax = []; 

ax = [ax; subplot(2,1,1)]; 
pcolor(lon(Lon2Use),-dep,v(Lon2Use,:)');shading('flat');colorbar 
ax = [ax; subplot(2,1,2)]; 
pcolor(lon(Lon2Use),-dep,PressureGeo(Lon2Use,:)');shading('flat');colorbar 
set(ax,'FontSize',20); 

我個人比較喜歡後一種解決方案,因爲如果更改子圖的數量,代碼不會更改。

相關問題