MATLAB: Patch option “facecolor” messes up point-markers

markers atop of "patch"opacityorder of objects in a figure

How to make a plot using the "facecolor" option in "patch" but still keeping markers of points displayed at the top of other objects?
If "FT.facealpha = 0.2" (line 25 of code) is commented out, point markers sit nicely at the top of other objects, as intented. If the opacity option is used, then markers appear at the bottom (or become transparent), which is an undesired effect. Plotting points at the end or using "uistack" doesn't resolve the issue. Please see the code below the message.
Many thanks,
Viki
figure;
hold on;
axis([-0.5 3.5 -0.5 3.5]);
axis equal; box on;
% set of 9 points with their (x,y) coords
P = [1 0; 0 1; 1 2; 2 1; 2 0; 2 2; 2 3; 3 0; 3 2];
% edges
E = [1 5; 3 7; 4 8; 7 9]; % each row defines vertices of an edge
for i = 1:size(E,1);
a = P(E(i,1),:); % coords of vertex "a" on edge [a,b]
b = P(E(i,2),:); % vertex "b"

line([a(1) b(1)],[a(2) b(2)], 'color', 'm', 'LineWidth',2);
end
% filled triangles
T = [2 3 4; 4 6 9]; % each row defines a triangle (vertices in P)
for i = 1:size(T,1)
a = P(T(i,1),:); % coords of vertex "a" in triangle [a,b,c]
b = P(T(i,2),:); % vertex "b"
c = P(T(i,3),:); % vertex "c"
FT.vertices = [a;b;c];
FT.faces = [1 2 3];
FT.facecolor = 'g';
FT.facealpha = 0.2; % COMMENT THIS LINE
patch(FT);
end
% plot points
h = plot(P(:,1),P(:,2),'o',...
'MarkerSize',10,'MarkerFaceColor','y','MarkerEdgeColor','b','LineWidth',2);
uistack(h,'top');

Best Answer

After doing the plot without the alpha, use
get(gcf, 'Renderer')
then run it with the alpha and fetch the renderer again. I bet on the second time you will find it has changed from something (zbuffer ?) to opengl .
If I am correct about that, try again without the alpha but afterwards
set(gcf, 'Renderer', 'opengl')
and see if the markers mess up.
If opengl is having an effect, then try giving the command
opengl software
and see if the plot starts working.
My guess is that Yes opengl is involved, and that No, software opengl will not fix the problm.
So... what you have to do is change everything to 3D. You can use 0 for the z for the patch part. For the plot() part, use a z value that is "nearer" to the viewer than the z value you gave for the patch. Even a z of 1e-6 for the plot() should work: anything to establish for the purposes of the renderer that the two items are not in the same plane and that one of them needs tobe rendered on top of the other because it is "closer".