Behaviour of barh stacked plot & FaceAlpha=0

3 views (last 30 days)
I’m having a little trouble understanding the behaviour of barh stacked plot. After running the code below you'll note that there is a black vertex(apparently belonging to the top of the [bmkVector] variable series) which, depsite being plotted first, is visible above the foremost yellow series. I would have expected the yellow bars to be totally in the foreground & so not being intersected by this bacl line (I hope my description is clear). Can anybody provide a solution to prevent this behaviour.
For context, what I'm ultimately trying to accomplish is to suspend the ptfFuturesVector & ptfFuturesVectorNeg series (i.e. both yellow) from a point coinciding with the top of the ptfVector bars. My solution is to plot them stacked above ptfVector & then to make ptfVector invisible (FaceAlpha=0).
bmkVector = [...
0.7028;
1.7649;
1.7354;
0.2245];
ptfVector = [...
0.5299;
2.5493;
1.4511;
0];
ptfFuturesVector =[...
0;
0;
2.1657;
0];
ptfFuturesVectorNeg =[...
0;
-1;
0;
0 ];
f = figure;
% h = axes(f);
barh(bmkVector,1,'FaceColor',[0.6078,0.6784,0.7490]);
hold(gca,'on');
barh(gca,ptfVector,0.7,'Stack','FaceColor',[0,0.3922,0.6078]);
barh(gca,[ptfVector,ptfFuturesVector,ptfFuturesVectorNeg],0.5,'Stack','FaceColor',[0.9216,0.7059,0.0784]);
childHandle = get(gca,'Children'); % New Series are put to top of Children Stack
set(get(childHandle(3),'Children'),'FaceAlpha',0,'EdgeAlpha',0,'EdgeColor',[0,0.3922,0.6078]); % Make 3rd child [ptfVector] invisible to give the effect of ptfFuturesVector and ptfFuturesVectorNeg starting from where ptfVector ends

Accepted Answer

Mark Whirdy
Mark Whirdy on 23 Nov 2012
Solution from Chrysanthos Placotas in mathworks.
" When you make the object transparent, it means that the objects behind it need to come on the "front". When the object comes on the front, its edges are traversing it, but the color does not change since it is opaque. "
Instead of making transparent, he suggests making same colour as background
set(get(childHandle(3),'Children'),'FaceColor',[0,0.3922,0.6078],'EdgeColor',[0,0.3922,0.6078]);

More Answers (0)

Categories

Find more on Discrete Data Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!