Value on top of grouped bar graph?

6 ビュー (過去 30 日間)
Ibro Tutic
Ibro Tutic 2017 年 8 月 7 日
編集済み: Soyeun Jung 2017 年 8 月 8 日
Assume we had
y=[2 3 4; 1 5 2; 6 2 5]
bar(y)
Would there be anyway to get the value of the bar graphs on top of the bars?
  1 件のコメント
Chad Greene
Chad Greene 2017 年 8 月 7 日
What version of Matlab are you using?

サインインしてコメントする。

回答 (1 件)

Soyeun Jung
Soyeun Jung 2017 年 8 月 7 日
編集済み: Soyeun Jung 2017 年 8 月 8 日
Hi Ibro,
You can calculate the bar offsets within each group and use the text function to plot the y values on top of each bar.
y = [2 3 4 ; 1 5 2; 6 2 5];
b = bar(y);
width = b.BarWidth;
for i=1:length(y(:, 1))
row = y(i, :);
% 0.5 is approximate net width of white spacings per group
offset = ((width + 0.5) / length(row)) / 2;
x = linspace(i-offset, i+offset, length(row));
text(x,row,num2str(row'),'vert','bottom','horiz','center');
end

カテゴリ

Help Center および File ExchangeData Distribution Plots についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by