필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Combined stacked and multi-bar barchart

조회 수: 1 (최근 30일)
Claudius Rosendahl
Claudius Rosendahl 2021년 4월 27일
마감: Claudius Rosendahl 2021년 5월 12일
I have three data columns (Y(:,1:3)) and their corresponding errors (Y(:,4:6)). What I want is Y(:,1) grouped with a stacked bar of Y(:,2:3).
The following code creates the attached plot.
figure;
b = bar(2:2:40,Y(:,1:3),'FaceColor','flat','EdgeColor','none');
X=cell2mat(get(b,'XData')).'+[b.XOffset];
b(1).FaceColor = [0 0 0];
b(2).FaceColor = [0.9 0 0];
b(3).FaceColor = [0 0.7 0];
hold on
errorbar(X(:,1),Y(:,1),Y(:,4),'LineStyle','none','Color',[0.6 0.6 0.6]);
errorbar(2:2:40,Y(:,2),Y(:,5),'LineStyle','none','Color',b(2).FaceColor*0.6);
errorbar(X(:,3),Y(:,3),Y(:,6),'LineStyle','none','Color',b(3).FaceColor*0.6);
hold off
So I want the green bar on top of the red bar (if green > 0, otherwise green bar below zero as usual). Repositioning the error bars is not a problem.
Is there any way to cleanly group stacked bars? I guess I could figure out some workaround by adding multiple bar plots together, but that seems messy and very time intensive....
Thanks!
(using Matlab 2020b)
  댓글 수: 3
Claudius Rosendahl
Claudius Rosendahl 2021년 4월 27일
"It's not clear to me where you want the green bar placed if <0???"
Sorry, that was not explained well. If green < 0, the green bar should be below the y=0 line, while the red bar stays where it is.
I don't mind switching red and green to make this work (e.g. green at the bottom, red above), that would not be a problem.
"Most of the time, you end up plotting one or the other (or both) with missing value placeholders [...]"
Well so it is just as I thought: no easy solution possible :-/
Thanks for the comment!
dpb
dpb 2021년 4월 27일
I was asking if you wanted the green and red stacked or still wanted a third bar if green <0.
If just use 'stacked' for those two columns, the negative values will still be below the y axis, just not offset horizontally from the red.

답변 (0개)

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by