How can I add error bars to a stacked bar graph?

17 ビュー (過去 30 日間)
Ellie Parr-Burman
Ellie Parr-Burman 2017 年 2 月 16 日
回答済み: Eliot Frank 2018 年 4 月 5 日
I want to add error bars to each section of my stacked bar graph,so that at each line there are error bars for that particular section of the stacked chart. Currently this is what code I am using.
y=[413.71 321.00 133.67 207.50 64.33 126.00; 279.32 190.00 105.33 192.00 54.33 118.33 ];
err=[20.22 58.59 58.05 10.61 8.08 24.58;15.7 36.29 24.79 1.00 14.50 19.60];
bar(y,'stacked');
hold on
errorbar(y,err);
But I am not getting the right result, instead getting something like this:
Can anybody help?
  3 件のコメント
Sean de Wolski
Sean de Wolski 2017 年 2 月 16 日
judging from the colormap >= 14b.
Ellie Parr-Burman
Ellie Parr-Burman 2017 年 2 月 21 日
R2016b

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

採用された回答

Ansh
Ansh 2017 年 6 月 20 日
Did you find an answer for this OP? I am stuck with the same problem, I'm using MATLAB 2014b at my work and MATLAB 2016b. A solution in either versions is sufficient.
  2 件のコメント
Ellie Parr-Burman
Ellie Parr-Burman 2017 年 6 月 20 日
I'm afraid not! I ended up changing the way I presented the data so didn't need it in the end, sorry I can't be of any help.
Ansh
Ansh 2017 年 6 月 21 日
If I find a solution, I shall repost on here as I think it will be difficult for me to present the data in a different way.

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

その他の回答 (2 件)

Eliot Frank
Eliot Frank 2018 年 4 月 5 日
For the OP: 2 problems: a line connects the error bars and the error bars are in the wrong place. Because of the stacked bars, you must accumulate the y values:
y=[413.71 321.00 133.67 207.50 64.33 126.00; 279.32 190.00 105.33 192.00 54.33 118.33 ];
err=[20.22 58.59 58.05 10.61 8.08 24.58;15.7 36.29 24.79 1.00 14.50 19.60];
bar(y,'stacked');
hold on
errorbar(cumsum(y')',err,'.k');
and the result:

Easwar Kumar Yarrabikki
Easwar Kumar Yarrabikki 2017 年 2 月 16 日
編集済み: Easwar Kumar Yarrabikki 2017 年 2 月 16 日
Hello Ellie, I did something like this. I hope it will work for you .I ran a below script on my machine and attached my results. I am not sure about your X data, I assumed it as flowing. I have tried this on R2013b and R2015a Let me know if this is not what you are looking for.....
y=[413.71 321.00 133.67 207.50 64.33 126.00; 279.32 190.00 105.33 192.00 54.33 118.33 ];
err=[20.22 58.59 58.05 10.61 8.08 24.58;15.7 36.29 24.79 1.00 14.50 19.60];
x=[1 2 3 4 5 6;7 8 9 10 11 12];
figure;
hold on
errorbar(x(1,:), y(1,:),err(1,:),'k')
errorbar(x(2,:), y(2,:),err(2,:),'r')
  2 件のコメント
Ellie Parr-Burman
Ellie Parr-Burman 2017 年 2 月 20 日
Hello,
Thank you for your answer! That didnt seem to work I'm afraid, instead I got something looking like this:
I'm not sure why it has ended up like this though!
Evyatar Cohen
Evyatar Cohen 2017 年 7 月 10 日
you need to add '.' after you choose your color: (errorbar(x(1,:), y(1,:),err(1,:),'k.')

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by