Displaying a value on top of bar chart

2 ビュー (過去 30 日間)
Bimal Ghimire
Bimal Ghimire 2020 年 9 月 3 日
コメント済み: Bimal Ghimire 2020 年 9 月 3 日
for i=1:20
A{i}=randi([100,1000]);
B{i}=randi([100,300]);
C{i}=randi([2,30]);
D{i}=randi([2,30]);
E{i}=randi([0,2]);
end
hold on;
index=10;
numNearbyCHs=20;
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0.04, 1, 0.96]);
for i=1:numNearbyCHs
y=[A{i}/5,B{i}/5,C{i}*5,D{i}*5];
bh = bar(i,y,'stacked','FaceColor', 'Flat');
% Choose a color map (using "lines" in this example)
if i~=index
colors = mat2cell(lines(numel(bh)),ones(numel(bh),1), 3);
set(bh, {'CData'}, colors)
else
colors = mat2cell(jet(numel(bh)),ones(numel(bh),1), 3);
set(bh, {'CData'}, colors)
end
arrayfun(@(i) text(bh(i).XEndPoints,bh(i).YEndPoints,num2str(bh(i).YEndPoints.','%0.1f'), ...
'verticalalignment','top','horizontalalign','center','Color','white'),[1:numel(bh)])
end
I would like to display value of E{i} on top of each stacked bar and each value of i on X-axis. Can somebody help me on this. I am really stuck on this. I would really appriate your help.
  1 件のコメント
Bimal Ghimire
Bimal Ghimire 2020 年 9 月 3 日
Thank you so much!

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

採用された回答

Cris LaPierre
Cris LaPierre 2020 年 9 月 3 日
編集済み: Cris LaPierre 2020 年 9 月 3 日
I'd add the following code at the bottom of your for loop
text(i,sum(y)+15,string(E(i)));

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by