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 CenterFile Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by