2012-04-24 66 views
3

我在圖中有4個子圖,並且想要標記它們a,b,c和d。我希望字母自動放置在每個子圖的左上角。我知道我可以手動添加文本,但有沒有更有效的方法來做到這一點?自動標記子圖

回答

4

你可以把這些方針的東西到腳本:

subplot(2,2,1) 
text(0.02,0.98,'a','Units', 'Normalized', 'VerticalAlignment', 'Top') 
subplot(2,2,2) 
text(0.02,0.98,'b','Units', 'Normalized', 'VerticalAlignment', 'Top') 
subplot(2,2,3) 
text(0.02,0.98,'c','Units', 'Normalized', 'VerticalAlignment', 'Top') 
subplot(2,2,4) 
text(0.02,0.98,'d','Units', 'Normalized', 'VerticalAlignment', 'Top') 

請注意,我假設你的次要情節被安排在一個2x2格,並且它們都是2D繪圖。如果這些假設不成立,請修改子圖的前兩個參數和/或向文本添加z座標。

2

您可以和指定的插曲想要的行數和增加使用功能字符的字母:

% data: 
myTriangle=(triang(100)); 
amplitudeFactor=[1 0.7 0.6 0.4 0.2]; 

% Plot, specifying number of lines in subplot: 
nLine=2; 
nPlot=length(amplitudeFactor); 
for ind=1:nPlot 
    subplot(nLine, ceil(nPlot/nLine),ind) 
    plot(myTriangle*amplitudeFactor(ind)) 
    set(gca,'YLim',[0 1]) 
    text(0.02,0.98,char('a' + ind - 1),'Units', 'Normalized', 'VerticalAlignment', 'Top') 
end