フィルターのクリア

Stacked Bar chart using structure, displaying putting values on each bar

4 ビュー (過去 30 日間)
% d7 = [0.1 0.2 0.15 0.2]
% d1= [0.3 0.2 0.15 0.15]
% d2= [0.2 0.15 0.15 0.15]
% d3= [0.1 0.15 0.1 0.15]
% d4= [0.1 0.1 0.2 0.15]
% d5= [0.1 0.1 0.05 0.15]
% d6= [0.1 0.1 0.2 0.05]
aor= [22.469 21.973 19.7 16.278]
%diameter = [0.3 0.2 0.15 0.15, 0.2 0.15 0.15 0.15,0.1 0.15 0.1 0.15, 0.1 0.1 0.2 0.15, 0.1 0.1 0.05 0.15, 0.1 0.1 0.2 0.05, 0.1 0.2 0.15 0.2];
diameter = [0.3 0.2 0.1 0.1 0.1 0.1 0.1; 0.2 0.15 0.15 0.1 0.1 0.1 0.2; 0.15 0.15 0.1 0.2 0.05 0.2 0.15; 0.15 0.15 0.15 0.15 0.15 0.05 0.2]
b = bar(aor,diameter, 'stacked')
xtickformat('%.2f')
grid on
newaor=aor.'
newarray = repmat(newaor,1,7)
text(newarray, cumsum(diameter),compose('%0.2f', cumsum(diameter)),'HorizontalAlignment','center','VerticalAlignment','top')
axis([14 24 0 2])
Hi,
I want to show the cumulative value of y in the stacked bar using the given data value provide. Could anyone please give me a hint for this? Thank you.

採用された回答

Simon Chan
Simon Chan 2022 年 2 月 21 日
The positions of the text should be in a row or column vector. Hence reshape it and will work.
While for the y-position of the text, you may adjust the margin to put the text in the required position. I use 0.06 in the following example.
Of course, you may also modify the fontsize or font color if needed.
d7 = [0.1 0.2 0.15 0.2];
d1= [0.3 0.2 0.15 0.15];
d2= [0.2 0.15 0.15 0.15];
d3= [0.1 0.15 0.1 0.15];
d4= [0.1 0.1 0.2 0.15];
d5= [0.1 0.1 0.05 0.15];
d6= [0.1 0.1 0.2 0.05];
aor= [22.469 21.973 19.7 16.278];
diameter = [0.3 0.2 0.1 0.1 0.1 0.1 0.1; 0.2 0.15 0.15 0.1 0.1 0.1 0.2; 0.15 0.15 0.1 0.2 0.05 0.2 0.15; 0.15 0.15 0.15 0.15 0.15 0.05 0.2];
b = bar(aor,diameter, 'stacked');
xtickformat('%.2f')
grid on
xpos=reshape(repmat(aor,size(diameter,2),1),[],1); % Make it to a column vector
ypos=reshape(cumsum(diameter'),[],1); % Make it to a column vector
text(xpos, ypos+0.06,arrayfun(@(x) sprintf('%0.2f',x),ypos,'uni',0),'HorizontalAlignment','center','VerticalAlignment','top','FontWeight','bold','FontSize',12)
axis([14 24 0 1.2]);
  1 件のコメント
Yeasir Mohammad Akib
Yeasir Mohammad Akib 2022 年 2 月 21 日
Thank you for the solution, I followed the same path (resolving it into row vector) to solve the problem later on.

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by