2013-05-10 72 views
0

我正在使用this question中的方法,試圖使每一組條紋都具有比例高度。這個方法會讓一個.1高度的條看起來與另一個垂直列的.5高度條的高度相同......我嘗試將'XLimMode'設置爲手動,將'XLim'設置爲常量值,但它不起作用。Matlab多條柱圖恆定高度軸

有誰知道如何確保所有條形圖的高度與SAME'y'軸(高度 - 軸線)成比例嗎?

回答

0

我找到了一個解決方案,首先找到所有值的最大值(totmaxaxes),然後在axes off之前添加該行。

totmaxaxes = max(n(:)); 

% generate "data" 
m = rand(40,10); 
[n x] = hist(m, 50); 

% the actual plotting 
figure; 
ma = axes('Position',[.1 .1 .8 .8]); % "parent" axes 
N = size(n,2); % number of vertical bars 
for ii=1:N, 
    % create an axes inside the parent axes for the ii-the barh 
    sa = axes('Position', [0.1+(ii-1)*.8/N, 0.1, .8/N, .8]); % position the ii-th barh 
    barh(x, n(:,ii), 'Parent', sa); 
    set(sa, 'Xlim', [0,totmaxaxes + totmaxaxes/40])  %ADD THIS! (+ totmaxaxes/4 just assures that your bar doesn't hit the top) 
    axis off; 
end