MATLAB: Painters renderer ignoring uistack and z values in R2014b

paintersr2014b

I'm writing a script that will be used on R2012b and R2014b. It works wonderfully in R2012b, but R2014b is ignoring z values and ignoring uistack order. Oddly enough, the problem only arises when I give any of the objects a z value. Here is an example:
figure('renderer','painters')
h0 = imagesc(peaks(100));
hold on
[C,h1] = contour(peaks(100),'color',.4*[1 1 1]);
clabel(C,h1);
h2 = plot(1:100,1:100,'b-','linewidth',3);
h3 = plot(1:100,(1:100).^1.2-30,'r','linewidth',3);
h4 = text(30,50,'some text near the top','color',[.98 .45 .02]);
h5 = text(25,75,1,'this text should be on top of everything');
Using uistack(h5,'top') does not fix the problem.
I don't understand why, but if I set the z value in h5 to 0, the problem goes away. Does anyone know why this is happening or how I can work around it? I need to stick with the painters renderer.

Best Answer

You need to learn about the SortMethod property on the axes. I talked about it in this post on the MATLAB Graphics blog. Because you put one text object at a different Z value from the rest of the scene, the axes guessed that you probably wanted depthsort. It sounds like you actually want childorder.