Odd behavior with using patch function and 'FaceAlpha' property

2 ビュー (過去 30 日間)
Ryan
Ryan 2011 年 12 月 17 日
Greetings,
I am seeing some odd behavior when I use the patch function with a 'FaceAlpha' value of anything besides 1. Here is a sample code that illustrates the problem:
figure(1);
clf(1)
x = linspace(0,1);
y = sin(x*4*pi);
c = 1.0*ones(1,2*length(x));
patch([x x(end:-1:1)],[zeros(1,length(x)) y(end:-1:1)],c,'FaceAlpha',0.9,'FaceColor',[0.7 0.8 1.0])
hold on
plot(x,y,'Color',[1 0 0],'LineWidth',2)
text(0.22,0,'Under','FontSize',14,'FontWeight','bold','FontName','times new roman','Color',[1 1 1],'BackgroundColor',[0 0 0])
grid on;
box on;
axis([0 1 -1 1]);
pause;
axis([0 0.9 -1 1])
When the X axis is changed from 0-1 to 0-0.9 the text is now rendered underneath everything else even though it is the last thing plotted and at the top of the children list. If I use a 'FaceAlpha' value of 1 the error does not occur. I have tried this with different platforms and different versions of Matlab and I get similar results.
Does anyone have any suggestion besides "Don't do that"?

回答 (1 件)

Walter Roberson
Walter Roberson 2011 年 12 月 17 日
The only renderer that supports alpha is OpenGL.
OpenGL has the odd property that lines (including text) that are in the same z plane as a surface, are always rendered in a particular order compared to the surface no matter which command was issued first (i.e., child order is ignored.)
I would say what the order is, except that I have encountered graphics cards that used exactly the other order -- a driver bug, yes, but not many of us are skilled in patching our OpenGL graphics drivers.
It is thus better to work around the problem rather than to count on your graphics card to render in a particular order. The work-around for this matter is to give objects explicit z coordinates corresponding to the rendering order you want, with objects on "top" given a greater z. It doesn't have to be a large z at all -- even z=1/1000 is enough to lift a line above a surface at z=0. Oh yes, and give your patch explicit z too or you will end up confused when you try to figure out what your code is doing.

カテゴリ

Help Center および File ExchangeGraphics Performance についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by