Patch option "facecolor" messes up point-markers
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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');
0 comentarios
Respuesta aceptada
Walter Roberson
el 23 de Jun. de 2013
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".
2 comentarios
Walter Roberson
el 25 de Jun. de 2013
OpenGL defines a virtual coordinate system in which the objects can be added in any order and the result is to be the same, dependent on the perspective and not the order of drawing. In order to be consistent, OpenGL had to define a rule about what is to happen if you have two objects in the same visual plane perpendicular to the line of sight. OpenGL defined that certain kinds of objects are to be "on top" of other kinds of objects in the same perpendicular plane. Not according to which one was constructed first, just according to the kind of object.
Because of this OpenGL defined order, there is nothing you can do with uistack() or the like, and no software flag you can set. Your choices about how to draw one thing above another are: (1) change the kinds of objects you draw, drawing upon research about OpenGL's priority hierachy; or (2) adjust your coordinates so that the object you want drawn above is "closer". That's usually the easier solution.
Note: OpenGL also has rules about what happens to 2D objects when you change the perspective. image objects are, by the way, 2D objects, so if you want to draw a line or marker "above" an image, you are safest to texture map the image onto a surface or patch (which are 3D objects)
Más respuestas (0)
Ver también
Categorías
Más información sobre Lighting, Transparency, and Shading en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!