Hi, I want to show boundaries of two variables in bar graph. However, when I add second variable to bar graph, smaller value of first value disappear in bar graph (such as y=7, y=8). I didnt find way to make it appears.
X=[5 4 3];
Y=[1 7 8];
bar(X)
hold on
bar(Y)

 채택된 답변

Chunru
Chunru 2021년 12월 6일
편집: Chunru 2021년 12월 6일

0 개 추천

X=[5 4 3];
Y=[1 7 8];
bar([X; Y]')
figure
bar(X)
hold on
bar(Y, 'FaceAlpha', .5); % transparency
figure
XMin = min(X, Y)';
XMax = max(X, Y)';
bar([XMin, XMax-XMin], 'stacked')
% Idea solution: Plot each bar individually
n = numel(X);
figure; hold on
for i=1:n
if X(i)>Y(i)
bar(i, X(i), 'r');
bar(i, Y(i), 'b');
else
bar(i, Y(i), 'b');
bar(i, X(i), 'r');
end
end

댓글 수: 4

Gokhan Kayan
Gokhan Kayan 2021년 12월 6일
편집: Gokhan Kayan 2021년 12월 6일
Thanks dear Chunru, second bar shows boundaries nicely, but only problem is colurs are different
Chunru
Chunru 2021년 12월 6일
The transparency make the overlapping colors different. Another non ideal solution is given above.
Chunru
Chunru 2021년 12월 6일
See the updated for an ideal solution.
Gokhan Kayan
Gokhan Kayan 2021년 12월 6일
편집: Gokhan Kayan 2021년 12월 6일
Oh. The last solution worked perfectly!. Thanks a lot for the help.

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

추가 답변 (1개)

KSSV
KSSV 2021년 12월 6일
편집: KSSV 2021년 12월 6일

1 개 추천

You can go ahead like this right?
X=[5 4 3];
Y=[1 7 8];
x = 1:3 ;
bar(x,[X;Y])
Or you can try:
bar([X' Y'],'stacked')

댓글 수: 1

Gokhan Kayan
Gokhan Kayan 2021년 12월 6일
Unfortunately, I dont want them like first way because i will draw line graph too. The graph will be sophisticated. Second graph adds y to x. I dont want summation.

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

카테고리

태그

질문:

2021년 12월 6일

편집:

2021년 12월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by