Surface AlphaData not working as expected

20 ビュー (過去 30 日間)
Lukas Wörle
Lukas Wörle 2022 年 4 月 6 日
編集済み: Lukas Wörle 2022 年 4 月 7 日
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

採用された回答

Voss
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 件のコメント
Lukas Wörle
Lukas Wörle 2022 年 4 月 7 日
編集済み: Lukas Wörle 2022 年 4 月 7 日
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'

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

タグ

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by