Making a Surface plot transparent
조회 수: 139 (최근 30일)
이전 댓글 표시
Ursula Trigos-Raczkowski
2022년 3월 1일
댓글: Ursula Trigos-Raczkowski
2022년 3월 1일
I am trying to make my surfaces transparent so I can see both when they are on top of each other/behind the other.
I have one surface for my aci/acj graph called CritCon and one for my inequalities ineq1/ineq2 called Condition
I have tried 'FaceAlpha', 0.3 in the surf( ) command as well as Alpha(0.3) after the surf() command, neither seems to work.
Thank you!
%define the set parameters
meshsize=.01; %changing this to be lower gives weird graphs
%gamma
g = 0.2;
%-------Param 0 ----------------
bj=2.34;
muj=0.4;
%define the range of x (deltai),y (betai) coordinates
mui=muj:.1*meshsize:7.6+muj;
bi=bj:.36587*meshsize:30;
%-------Param 0 ----------------
% Mesh Grid
[X,Y] = meshgrid(mui,bi);
%------------------------Inequalities---------------------------------------------------------
%Inequality 1 is for Sij>0 and Ri>1.
%Inequality 2 is for Sji>0 and Rj>1.
ineq1= Y > (2*bj.*(X+g).*(g+muj).*(X+g+muj))./(bj.*g.*(X-muj)+(g+muj).*(X+2*g+muj).*(g+2*muj));
ineq2= Y < (bj.*(X+g).*(2*X+g).*(X+2*g+muj))./(bj.*g.*(X-muj)+2.*(X+g).*(g+muj).*(X+g+muj));
aci = (1+(-2).*X.*(g+2.*X).^(-1).*Y.*((-1).*g+(-1).*X+Y).^(-1))<=(0);
acj = (1+(-2).*bj.*(bj+(-1).*g+(-1).*muj).^(-1).*muj.*(g+2.*muj).^(-1))<=(0);
%------------------------Inequalities---------------------------------------------------------
Condition = ineq1.*ineq2;
Condition(Condition==0) = NaN;
CritCon = aci.*acj;
CritCon(CritCon==0)=NaN;
%---------------------------Surfaces-------------------------------------
surf(X,Y,CritCon,'EdgeColor', '[0.3010, 0.7450, 0.9330]','FaceAlpha',0.3)
hold on
surf(X,Y,Condition,'EdgeColor', '[0.6350, 0.0780, 0.1840]','FaceAlpha',0.3)
%---------------------------Surfaces-------------------------------------
%----------------------------Labels--------------------------------------
xlabel('\mu_i')
ylabel('b_i')
view(0,90)
title('R_i,R_j>1 , S>0 (and crit cond) when \mu_j=0.4, b_j=2.34.')
%----------------------------Labels--------------------------------------
hold off
댓글 수: 1
채택된 답변
Benjamin Kraus
2022년 3월 1일
편집: Benjamin Kraus
2022년 3월 1일
Your surface plots are each roughly 7500x7500 faces, and most (all) monitors have a resolution that is much lower than that. This means that each "face" of your surface is smaller than a pixel, but the edges between the faces are also larger than the faces themselves. This means what you are seeing is entirely the edge color, not the face color. Your best bet is to turn off the edge color, so all you can see are faces, then the transparency will work.
s1 = surf(X,Y,CritCon,'EdgeColor','none','FaceAlpha',0.3,'FaceColor',[0.3010, 0.7450, 0.9330])
hold on
s2 = surf(X,Y,Condition,'EdgeColor','none','FaceAlpha',0.3,'FaceColor', [0.6350, 0.0780, 0.1840])
댓글 수: 3
Benjamin Kraus
2022년 3월 1일
Looking at the comments in your code:
meshsize=.01; %changing this to be lower gives weird graphs
The "weird graphs" you are seeing were because of the mix of edges and faces, and part of the issue is due to what is called "aliasing". If you draw a surface with faces that are roughly between 0.5 pixels and 1.5 pixels across, then the effect is that each face will alternate between 0 and 1 pixel wide, so you will see every other face (or maybe ever 2nd face or every 3rd face). In addition, with your original code you were seeing alternating faces and edges, and the faces were semi-transparent but the edges were not. This can result in weird banding patterns on the picture.
Once I replaced your two lines creating surface plots with the two lines above, I could replace mesh size with 0.1 and got basically the same picture but much faster.
추가 답변 (1개)
Johan
2022년 3월 1일
I think FaceAlpha does work but your mesh size is so small that you only see the edges plotted which are not transparent in your case. You can use EdgeAlpha to see if the graph looks better that way.
댓글 수: 2
Walter Roberson
2022년 3월 1일
Good point.
Most of the time I use Edgecolor 'none' to avoid that problem
참고 항목
카테고리
Help Center 및 File Exchange에서 Lighting, Transparency, and Shading에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!