Surface AlphaData not working as expected
20 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
Voss
2022 年 4 月 6 日
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 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Surface and Mesh Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
