user3271929
user3271929

Reputation: 327

Plotting with transparency

I have to plot two curves as below that overlap each other. How I can make the overlapping area transparent, in order that the lower curve is visible? In the overlapping area, I can currently only see the top curve.

x=0:0.01:2*pi;                  %#initialize x array
y1=sin(x);                      %#create first curve
y2=sin(x)+.5;                   %#create second curve
X=[x,fliplr(x)];                %#create continuous x value array for plotting
Y=[y1,fliplr(y2)];              %#create y values for out and then back
fill(X,Y,'b');                  %#plot filled area
%*****************
hold on
x=0:0.01:2*pi;                  %#initialize x array
y1=sin(2.*x);                   %#create first curve
y2=sin(2.*x)+.5;                %#create second curve
X=[x,fliplr(x)];                %#create continuous x value array for plotting
Y=[y1,fliplr(y2)];              %#create y values for out and then back
fill(X,Y,'b');                  %#plot filled area

Upvotes: 2

Views: 2922

Answers (1)

Sam Roberts
Sam Roberts

Reputation: 24127

Replace your last command fill(X,Y,'b'); with:

h = fill(X,Y,'b');

to get a handle to the patch object it creates. Then type:

set(h, 'FaceAlpha', 0.5)

enter image description here

Does that do what you need?

Upvotes: 3

Related Questions