Surface AlphaData not working as expected

20 visualizaciones (últimos 30 días)
Lukas Wörle
Lukas Wörle el 6 de Abr. de 2022
Editada: Lukas Wörle el 7 de Abr. de 2022
Hi,
I am trying to get to a surface plot where measured data is opaque and extrapolated data is shown but transparent to indicate this data is less trustworthy. I can't manage to set two different alpha values with the AlphaData property assuming it takes values between 0 and 1 or 0 and 255.
MWE:
% generate grid
[x,y] = meshgrid(1:10,1:10);
z = x+y;
% select opaque points
idx = x>=3 & x<=6 & y>=3 & y<=6;
a = double(idx);
a(a==1) = 1;
a(a==0) = 0.5;
% plot
figure
surf(x,y,z,'FaceAlpha','flat','FaceColor','flat','AlphaData',a)
xlabel 'x'
ylabel 'y'
zlabel 'z'
This leads to the following result, the surfaces which are not selected to be opaque are completely transparent:
If I set the alpha to 1 (or 255) for all points I get the following result:
a(a==1) = 1; %255;
a(a==0) = 1; %255;
What I actually want to achieve is to have the selected points/faces as in picture 1 and the remaining part of the surface as in picture 2. I don't get how AlphaData is interpreted, especially since it turns everything transparent when I set all values to 1 or 255. I also tried different settings for FaceAlpha and FaceColor which does not change the general behaviour of the transparency.
Cheers,
Lukas

Respuesta aceptada

Voss
Voss el 6 de Abr. de 2022
You can set AlphaDataMapping to 'none' to get those Alpha values to be interpretted correctly:
% generate grid
[x,y] = meshgrid(1:10,1:10);
z = x+y;
% select opaque points
idx = x>=3 & x<=6 & y>=3 & y<=6;
a = double(idx);
a(a==1) = 1;
a(a==0) = 0.5;
% plot
figure
surf(x,y,z,'FaceAlpha','flat','FaceColor','flat','AlphaData',a,'AlphaDataMapping','none')
xlabel 'x'
ylabel 'y'
zlabel 'z'
  1 comentario
Lukas Wörle
Lukas Wörle el 7 de Abr. de 2022
Editada: Lukas Wörle el 7 de Abr. de 2022
Thanks, that works. Do you also know how to get that to work with FaceAlpha set to 'interp'? More of a curious question to understand how this is meant to be used.
% generate grid
[x,y] = meshgrid(1:10,1:10);
z = x+y;
% select opaque points
idx = x>=3 & x<=6 & y>=3 & y<=6;
a = double(idx);
a(a==1) = 1;
a(a==0) = 0.25;
% plot
figure
surf(x,y,z,'FaceAlpha','interp','FaceColor','interp','AlphaData',a,'AlphaDataMapping','none')
xlabel 'x'
ylabel 'y'
zlabel 'z'

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Surface and Mesh Plots en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by