필터 지우기
필터 지우기

colour variation (transparency) on the overlapping bars of 2 bar charts

조회 수: 6 (최근 30일)
Alberto Acri
Alberto Acri 2023년 8월 6일
답변: DGM 2023년 8월 6일
Hi! I have two bar charts placed in the same figure:
load C.mat
figure
hbh = barh(C(:,1), C(:,[2 3]),'stacked');
cm = ['b'; 'r'];
for k = 1:numel(hbh)
hbh(k).FaceColor = cm(k,:);
hbh(k).EdgeColor = 'k';
% hbh(k).FaceAlpha = 0.2;
end
legend('Graph 1', 'Graph 2', 'Location','best')
I would like to obtain a result like this (colour variation on the overlapping bars):
I have applied the 'FaceAlpha' command but it only changes the transparency of the bars.

채택된 답변

DGM
DGM 2023년 8월 6일
The transparency has no effect because there's nothing behind it. You're stacking the bars end-to-end, not on top of each other.
y1 = 1:10;
y2 = fliplr(y1);
% two bar plots, one atop the other
hbh(1) = barh(y1); hold on
hbh(2) = barh(y2);
cm = ['b'; 'r'];
for k = 1:numel(hbh)
hbh(k).FaceColor = cm(k,:);
hbh(k).EdgeColor = 'k';
hbh(k).FaceAlpha = 0.2;
end
legend('Graph 1', 'Graph 2', 'Location','best')

추가 답변 (0개)

카테고리

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

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by