# Making a Surface plot transparent

156 ビュー (過去 30 日間)
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 件のコメント-1 件の古いコメントを表示-1 件の古いコメントを非表示
Walter Roberson 2022 年 3 月 1 日
Edgecolor would normally be numeric not character vector.

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

### 採用された回答

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 件のコメント1 件の古いコメントを表示1 件の古いコメントを非表示
Benjamin Kraus 2022 年 3 月 1 日
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.
Ursula Trigos-Raczkowski 2022 年 3 月 1 日
Thank you again, this is extremely helpful.

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

### その他の回答 (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 件のコメントなしを表示なしを非表示
Ursula Trigos-Raczkowski 2022 年 3 月 1 日
That doesn't seem to work either :/
Thanks!
Walter Roberson 2022 年 3 月 1 日
Good point.
Most of the time I use Edgecolor 'none' to avoid that problem

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

### カテゴリ

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