필터 지우기
필터 지우기

Vertically overlapping 'stacked' bars

조회 수: 4 (최근 30일)
Philip Berg
Philip Berg 2017년 1월 30일
답변: Iddo Weiner 2017년 2월 1일
I have some data I want to display as a bar plot. But, some of the values are positive and some are negative, this makes the bars overlap, vertically, when using 'stacked'. Now, at least for me, each group only has two bars stacked on top of each other. Instead of MATLAB's default, I would like to display half of the side (right or left) in the color of on of the bars, and the other side in the other color of the other to indicate how big the "hidden" bar is. Thanks for any help. (MATLAB R2015b)

답변 (2개)

Iddo Weiner
Iddo Weiner 2017년 1월 31일
Hope I understood correctly.. Try this:
a = rand(5,1);
b = -1 * rand(5,1);
data = [a b];
bar(data)
legend('positive value','negative value')
  댓글 수: 1
Philip Berg
Philip Berg 2017년 1월 31일
If you had used 'stacked', sorry, I only noted this in the title so I have slightly edited my post. But, you also don't have issues with "hidden" bars or any form of vertical overlay, which you will get if you change to 'stacked'.

댓글을 달려면 로그인하십시오.


Iddo Weiner
Iddo Weiner 2017년 2월 1일
Philip, I think I understand - you insist on having your bars stacked, but when you do so with negative values, this "hides" some of the data, right?
Here's an idea - make your bars semi-transparent:
a = rand(5,1);
b = -1 * rand(5,1);
data = [a b];
bar(data,'stacked')
alpha (0.5)
legend('positive value','negative value')
This way you see the hidden data.. Does this help?

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by