Reputation: 249
I would like to draw various curves in the same figure, and color the area between the respective curve and a given basevalue.
Here is a toy example of code that I hoped was working, but for some reason the function area
does not work the way I would expect:
x = 0:1/30:30;
y = sin(x);
figure
hold on
for i = 1:3:10
area(x,y+i,i)
end
What I would expect and need is something like this:
However, what Matlab is plotting is this:
Is it just too late and I should go to bed or what is the problem here?
Upvotes: 1
Views: 230
Reputation: 26069
just use fill
or patch
instead of area
:
x = linspace(0,10*pi)
y = sin(x);
figure
hold on
for i = 1:3:10
patch(x,y+i,i);
end
note that I changed the x limit so y will end on the same value it started with to get the crossed vertical line. For a more generic treatment look here.
Upvotes: 2