MATLAB: Is the “Layer” property of the axes ignored when the axes contains objects with ‘EraseMode’ property other than ‘normal’ in MATLAB

backgroundbottomeraseerasemodeMATLABmodenonenormaltopxor

I use the following code to draw a patch object:
x = [0 0;0 1;1 1];
y = [1 1;2 2;2 1];
z = [1 1;1 1;1 1];
tcolor(1,1,1:3) = [1 1 1];
tcolor(1,2,1:3) = [.7 .7 .7];
bb = patch(x,y,z,tcolor, 'erasemode', 'background');
set(gca, 'Layer', 'top');
grid on;
Since I have set the 'Layer' property of the axes to 'top', I expect the patch objects to render behind the grid lines. However, in the resulting plot, the patch objects are rendered in front of the grid lines, contrary to the 'Layer' property setting.

Best Answer

Objects with 'EraseMode' property other than 'normal' are rendered last after all other components of the figure. Therefore, they cannot obey the 'Layer' property of the axes. Only objects with 'EraseMode' set to 'normal' work with the 'Layer' property of axes.