MATLAB: Can I specify the stacking order of graphics objects when using hgtransform objects

axesgraphics objectshgtransformlayerlayerslineMATLABorderstacking

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

Lacking other answers, I submitted this as a technical support request / bug report. Their response was that this is not expected bevaviour and is the result of a bug in the (default) 'painters' rendering engine. Hopefully it will be fixed in a future version of matlab.
Meanwhile, the problem can be averted by using a different rendering engine, e.g. by setting
set(gcf,'renderer','zbuffer')
This gives the expected stacking behaviour for graphics objects.
However, if you want to export the figure into a vector format such as EPS, then you are stuck because painters rendering engine is the only one which can do that.