Set(...'facealpha'..) gives me a very odd problem

Dear all,
Intro: I have worked my entire day on this problem and I cannot seem to be able to solve it. The question also appears on stackoverflow: http://stackoverflow.com/posts/22377469/revisions
Now the problem essentially is that while executing the command:
set([a,b,c,d],'edgecolor','none','facealpha',0.05);
The functionalities such as 'plot' and 'bar' stops working.
Code:
h = figure('Units', 'pixels', ...
'Position', [700 500 1000 500]);
axes('Position',[0.1 0.50 0.85 0.45])
hold
%First fill:
z = [str(1) str(end) str(end) str(1)];
y = [4 4 10 10];
a = fill(z,y,[0 0.8 0.0])
%Second fill:
y2 = [0 0 4 4];
b = fill(z,y2,[0.8 0.0 0.0])
%set(a,'edgecolor','none','facealpha',0.1);
%Third fill
y3 = [0 0 3 3];
c = fill(z,y3,[1 0.0 0.0])
%set(a,'edgecolor','none','facealpha',0.1);
%Fourth fill
y4 = [10 10 20 20];
d = fill(z,y4,[0.8 0.0 0.0])
size(str)
e = plot(str',bg1(1:1:limit),'b.');
f = plot(str(1:5:end),cgm1(1:1:limit/5),'.','color',[0.5 0.5 0.5]);
%set([a,b,c,d],'edgecolor','none','facealpha',0.05);
axis([min(str) max(str) 0 20])
datetick('x', 'HH:MM','keeplimits');
set( gca , 'FontName' , 'Helvetica' );
ylabel('Blood Glucose [mmol/L]');
legend([e,f],'No feedforward','CGM signal','location','NorthEast')
hold off
axes('Position',[0.1 0.1 0.85 0.35])
hold
bar(str(1:5:end),u(1:1:limit/5,1),1);
axis([min(str) max(str) 0 max(u(:,1))])
This result in following picture:
While I want to add transparency I uncomment the line of code:
set([a,b,c,d],'edgecolor','none','facealpha',0.05);
and the result, of the exact same plot, become following:
Now as you might notice, something goes completely wrong. The plot function suddenly gets non-smooth (which is not the case for the data) and the function bar suddenly do not use the correct interval. I have absolutely no idea what is going on. Let me know if you have any suggestions or ideas to what is causing the set function to turn my plot into a complete mess.
Thanks a lot, I appreciate it!
Can you help me? Thanks!

Respuestas (1)

Kelly Kearney
Kelly Kearney el 13 de Mzo. de 2014
When alpha causes weird behavior, my first instinct is to check the renderer. If you run
set(gcf, 'renderer', 'zbuffer')
after the script with the set([a;b;c;d], 'facealpha', ...) uncommented does, everything look okay except for the now-missing transparency?

8 comentarios

I am not certain that I understand you.
Do you want me to uncomment:
set([a,b,c,d],'edgecolor','none','facealpha',0.05);
and instead try this:
set(gcf, 'renderer', 'zbuffer')
what should be expected when performing what you suggest?
Kelly Kearney
Kelly Kearney el 13 de Mzo. de 2014
Editada: Kelly Kearney el 13 de Mzo. de 2014
No, create the figure as you described in your code, with the facealpha property set to 0.05 for those objects. After the figure is created, add my line, which will change the figure renderer from OpenGL to zbuffer.
The OpenGL renderer is the only one that Matlab offers that supports transparency, but it can act up on a lot of computers (depends on operating system, hardware/software graphics options, etc).
If changing the renderer fixes the weirdness, then there are some things you can try to get OpenGL working properly (though it isn't always fixable).
Adding your line in the end of the plotting rutine actually removes the transparency but also makes the lines in the correct manner. This means that this code:
set(gcf, 'renderer', 'zbuffer')
removes the transparency but actually makes the plot work. I am not an expert on this subject - but what does this tell you?
Thanks for your help I appreciate it!
Stefan
Stefan el 13 de Mzo. de 2014
Does this mean that it potentially is my computer that is causing this problem and that creating this plot on another machine may solve the problem?
Yes, this means OpenGL is the culprit. You can read up on potential solutions here:
If you're on a PC, issuing
opengl software
might be a quick fix. If that doesn't work, or if you're on a Mac and don't have a software option, you can try some of the Driver Bug workarounds listed on that page.
If none of that works, you can try another machine. Or, like me (who, over 10 years and dozens of different computers, has never been blessed with a reliable Matlab-OpenGL interaction), learn to live without transparency... in this example, use lighter colors for the fill regions and uistack the fill patches under the other objects.
Stefan
Stefan el 14 de Mzo. de 2014
Interesting stuff. I will try on another machine. The opengl software does not give a solution (I am on a PC).
Thanks for your comments!
Stefan
Stefan el 14 de Mzo. de 2014
Tried on another Lenovo machine and also by using the area function instead of the fill function. This still does not work and are extremely frustating. I will go the 50km to go to a friend who has a Mac. Fingers crossed lol.
Stefan
Stefan el 14 de Mzo. de 2014
Problem persist.

Iniciar sesión para comentar.

Categorías

Más información sobre Creating, Deleting, and Querying Graphics Objects en Centro de ayuda y File Exchange.

Preguntada:

el 13 de Mzo. de 2014

Comentada:

el 14 de Mzo. de 2014

Community Treasure Hunt

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

Start Hunting!

Translated by