Bizare problem with FaceAlpha and rendering

16 views (last 30 days)
Hi,
I have a very strange problem so i want to create a series of patch objects and plot them together (for simplicity in this example there is only one object):
X =900000;
Y =115;
Z =100;
origin = [100000,5,100];
MINX = 0.1;
MAXX = 1000000;
MINY = 0.000001;
MAXY = 120;
MINZ = 0.01;
MAXZ = 1000;
clf
h(1) = axes('Position',[0.2 0.2 0.6 0.6]);
vert = [origin(1) origin(2) origin(3); ...
origin(1) origin(2)+Y origin(3); ...
origin(1)+X origin(2)+Y origin(3); ...
origin(1)+X origin(2) origin(3); ...
origin(1) origin(2) origin(3)+Z; ...
origin(1) origin(2)+Y origin(3)+Z; ...
origin(1)+X origin(2)+Y origin(3)+Z; ...
origin(1)+X origin(2) origin(3)+Z];
fac = [1 2 3 4; ...
2 6 7 3; ...
4 3 7 8; ...
1 5 8 4; ...
1 2 6 5; ...
5 6 7 8];
hold on;
bob = patch('Faces',fac,'Vertices',vert,'FaceColor','b','FaceAlpha',0.5);
light('Position',[1 3 2]);
light('Position',[-3 -1 3]);
material shiny;
alpha('color');
alphamap('rampdown');
camlight(45,45);
lighting phong;
view(30,30);
set(gca,'XLim',[MINX MAXX],'YLim',[MINY MAXY],'ZLim',[MINZ MAXZ]);
set(gca,'XScale','log','YScale','log','ZScale','log');
%set(gcf, 'Renderer', 'OpenGL');
Ok so the issue is that up until the point where i set the scales to log the objects are semi transparent (FaceAlpha 0.5), however when set they then become solid again and no matter what value of FaceAlpha they remain this way.
I looked around and found a suggestion to set the rendering to open glide (last line of code which is commented) but this is when it becomes even more strange. If you run the code with the last line above you do get transparent objects but the log scales change completely and appear to be normal scales again despite being set to log values!
Can anyone help me with this? I need to get transparent objects with the log scales obtained with the code above (minus the openGl render code which changes the log scale)
Also has anyone encountered this problem before? Why on earth would changing the renderer change the log scale of the plot???
Thanks
Matt
EDIT: BTW im using r2008b EDIT: OK so i just found that openGl doesnt support log scales so thats one problem sorted but how then can i get transparent objects with log scales in matlab??

Accepted Answer

Desiree
Desiree on 10 Aug 2011
Unfortunately you won't be able to create a plot with log scales and transparent objects.
OpenGL is the only renderer that supports transparency, but it does not support log scales. The other renderers (ZBuffer, Painters) do support log scales, but no transparency. You can find more information on renderers here:
  6 Comments
Oleg Komarov
Oleg Komarov on 10 Aug 2011
@Desire: update to the graphics engine when? Will it include also upgrades to the customization of the axes?
Matthew O'Brien
Matthew O'Brien on 10 Aug 2011
@Oleg - an upgrade is definitely needed. For both this problem and axes. I find it easier to export the image and tidy the axes in photoshop! One thing thats very annoying is the fact that the saved tiff file is not always whats on screen!

Sign in to comment.

More Answers (3)

W Perkins
W Perkins on 7 Feb 2013
Edited: W Perkins on 7 Feb 2013
Depending on the complexity of your object, you could try logarithmically transforming your data, plotting, and changing the scale labels (not the scale itself), and the transparency function is preserved. For example:
duration = [0.2 1 10 60 300 600 1200 1800 3600]; %sec
x = log(duration);
y = 9:-1:1;
patch([x fliplr(x)],[y -fliplr(y)],[1 0 0],'edgecolor','none','facealpha',0.5)
set(gca,'xtick',log(duration))
labels=num2cell(duration);
set(gca,'xticklabel',labels)

Felix
Felix on 28 Dec 2014
Hi, if you use the latest version of MATLAB (2014) you can also tune up the ticklabels so they are displayed as 10^... by using latex strings.
powers=-10:1:10;
a=cell(length(powers));
for i=1:length(powers)
a(i)=cellstr(strcat('10^{',num2str(powers(i))));
a(i)=cellstr(strcat(a(i),'}'));
end
set(gca,'YTick',log10(10.^powers));
set(gca,'YTicklabel',a);
a than is a cell array containing Strings like 10^{-10}, 10^{-9}, ...
now you have a logarithmic scale and transparency!

himura
himura on 24 Sep 2022
Edited: himura on 24 Sep 2022
Pretty old question, it is 2022 now and this still seems to not be supported (please correct me if I am wrong).
I am here to pitch another workaround: simply setting the color to be lighter. The example code here is for semilogy(), but it works for semilogx() and loglog()
x_axes = -10:0.1:10;
y_axes = x_axes .^ 2;
semilogy(x_axes, y_axes, '*', Color = [0 0 1]); % without transparency
semilogy(x_axes, y_axes, '*', Color = [0.7 0.7 1]); % with "transparency". it only seems transparent, but not really
% or
semilogy(x_axes, y_axes, '*', 'Color', [0 0 1]); % without transparency
semilogy(x_axes, y_axes, '*', 'Color', [0.7 0.7 1]); % with "transparency". it only seems transparent, but not really

Categories

Find more on Labels and Annotations in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!