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 CenterFile Exchange에서 Surface 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