I want to control the stacking order of graphics objects in a 2D plot, so that e.g. a line graph appears on top of a rectangle.
As discussed in Answer 93160, this can be done by controlling the order of handles in the Children propert (typically by setting it to a permutation of itself).
However, this does not work when the graphics objects (or a group they are part of) have an hgtransform object as a Parent, e.g. to translate the objects to a different location.
For example, I can make a plot and a filled rectangle which partially overlays it.
x = 0:5:360;hp = plot(x,sind(x));hr = rectangle('Position',[180,-1,180,1],'FaceColor','r');
I want the graph to overlay the rectangle, which I can achieve by changing the order of the Children.
set(gca,'Children',[hp; hr]);
The same applies if they are part of an hggroup.
hg = hggroup;set(hp,'Parent',hg);set(hr,'Parent',hg);set(hg,'Children',[hp; hr]);
However, if I use an hgtransform object to translate the objects or the group
TM = makehgtform('translate',[90 1 0]);hgt = hgtransform('Matrix',TM);set(hg,'Parent',hgt);
then the rectangle is always on top no matter which order I set the Children objects in.
set(hg,'Children',[hp; hr]);
does not affect the overlay order any more.
Sometimes, part of the plot will appear on top, so this behaviour is not entirely consistent. Am I doing something wrong, or is this a Bug or a 'feature'?
Best Answer