Surface AlphaData not working as expected
20 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Lukas Wörle
am 6 Apr. 2022
Bearbeitet: Lukas Wörle
am 7 Apr. 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
0 Kommentare
Akzeptierte Antwort
Voss
am 6 Apr. 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 Kommentar
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Surface and Mesh Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
