Set(...'facealpha'..) gives me a very odd problem
Mostrar comentarios más antiguos
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!
1 comentario
Stefan
el 13 de Mzo. de 2014
Respuestas (1)
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
Stefan
el 13 de Mzo. de 2014
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).
Stefan
el 13 de Mzo. de 2014
Stefan
el 13 de Mzo. de 2014
Kelly Kearney
el 14 de Mzo. de 2014
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
el 14 de Mzo. de 2014
Stefan
el 14 de Mzo. de 2014
Stefan
el 14 de Mzo. de 2014
Categorías
Más información sobre Creating, Deleting, and Querying Graphics Objects en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!