2016-03-27 104 views

回答

2

question I linked在評論是這樣做的一種方式。還有其他方法可以自定義條形圖,例如參見this article(雖然從HG2開始,內部已經發生了很大變化,因此到達內部並檢索我們需要的數據變得更加棘手)。 (請注意,我使用未記錄的屬性來獲取由條形圖創建的隱藏「Face」圖形對象):如果您願意深入挖掘,那麼應該使用MATLAB R2014b和更新的解決方案

Y = rand(3,4); 
h = bar(Y); 
drawnow % this is needed for some reason! 

opts = {'VerticalAlign','middle', 'HorizontalAlign','left', ... 
    'FontSize',8, 'Rotation',90}; 
for i=1:numel(h) 
    clr = h(i).Face.ColorData(1:3); 
    vd = h(i).Face.VertexData; 
    xy = double(vd(1:2,2:4:end) + vd(1:2,4:4:end))/2; 
    for j=1:size(xy,2) 
     text(xy(1,j), xy(2,j), sprintf(' %.2g',xy(2,j)), ... 
      'Color','k', opts{:}) 
    end 
end 

barplot