colour variation (transparency) on the overlapping bars of 2 bar charts
6 次查看(过去 30 天)
显示 更早的评论
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')
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1451412/image.png)
I would like to obtain a result like this (colour variation on the overlapping bars):
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1451417/image.jpeg)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1451422/image.png)
I have applied the 'FaceAlpha' command but it only changes the transparency of the bars.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1451427/image.png)
0 个评论
采纳的回答
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Discrete Data Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!