Dear Antoine and Samuel,<div><br></div><div>Thanks for the replies. I am using Antoine's function. It is working great!.</div><div>Thanks Antoine, for everything :)</div><div>Regards,</div><div>Sumit<br><br><div class="gmail_quote">
On Wed, Oct 5, 2011 at 8:54 AM, Antoine Monmayrant <span dir="ltr"><<a href="mailto:antoine.monmayrant@laas.fr">antoine.monmayrant@laas.fr</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Le 04/10/2011 22:41, Samuel Gougeon a écrit :<div><div></div><div class="h5"><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Le 04/10/2011 15:47, Sumit Adhikari a écrit :<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hello All,<br>
<br>
If I have two curves then how do I shade the area between two curves in scilab.<br>
<br>
I am plotting data files and using scilab plot function.<br>
</blockquote>
There are at least 4 ways for doing that. The best one depends on if your curves<br>
share the same x or not, and/or if they are crossing each others or not...<br>
<br>
After a plot, you may use e = gce(); e=e.children(1); and then<br>
either e.polyline_style=5; e.foreground=<index of the color you want><br>
or e.fill_mode="on"; e.background=<index of the color you want><br>
xfpoly(...) could also be used.<br>
Anyway, you will likely have to complete your data by adding a heading<br>
and a trailing well-chosen point to each curve.<br>
<br>
Have a try and optimize according to your data.<br>
<br>
The area between both curves may also be considered as a polygone to be filled.<br>
<br>
HTH<br>
Samuel<br>
</blockquote>
<br></div></div>
For two curves y1 and y2 that share the same x axis, I have made this quick and dirty function:<br>
<br>
BetweenCurves(x,y1,y2);<br>
<br>
Here is an example:<br>
<br>
x=[-10:10];y1=x+10;y2=x.*x;<br>
BetweenCurves(x,y1,y2);<br>
<br>
<br>
Here is the source code below:<br>
<br>
<br>
//////////////////////////////<u></u>//////////////////////////////<u></u>//////////////////////////////<u></u>//////////////////////////////<u></u>//////<br>
// Plot area between two curves<br>
function [h,epoly,ey1,ey2]=<u></u>BetweenCurves(x,y1,y2,<u></u>varargin)<br>
//<br>
// Plots two curves and fill the area in between<br>
//<br>
// INPUTS:<br>
// x vector (1,n) of horizontal coordinates<br>
// y1 vector (1,n) value of 1st curve y1(x)<br>
// y2 vector (1,n) value of 2nd curve y2(x)<br>
// -- optional inputs: pairs "keyword","value" --<br>
// "handle",h handle to the graphic window to use<br>
// "axis",a handle to the graphic axis to use<br>
// "foreground", colorid id of the color to use for painting the area<br>
// "background", colorid id of the color to use for curves stroke<br>
//<br>
// OUTPUTS:<br>
// h handle to the graphic window used<br>
// epoly handle to the polygone that fill the area in between<br>
// ey1 handle to first curve<br>
// ey2 handle to second curve<br>
<br>
//default values for optional argument<br>
hfig=-1;<br>
background=%nan;<br>
foreground=%nan;<br>
// scan varargin for optional parameter pairs (they can appear in any order)<br>
for i=1:2:length(varargin)<br>
keyword=varargin(i);<br>
value=varargin(i+1);<br>
select keyword<br>
case "handle" then<br>
hfig=value;<br>
scf(hfig);<br>
case "axis" then<br>
axis=value;<br>
sca(axis);<br>
hfig=axis.parent;<br>
case "background" then<br>
background=value;<br>
case "foreground" then<br>
background=value;<br>
end<br>
end<br>
// special treatment for handle (aka hack alert)<br>
if typeof(hfig) ~= "handle" then<br>
hfig=scf();<br>
end<br>
h=hfig;<br>
scf(hfig);<br>
xfpoly([x,x($:-1:1)],[y1,y2($:<u></u>-1:1)]);<br>
epoly=gce();<br>
plot(x,y1);<br>
ey1=gce();<br>
plot(x,y2);<br>
ey2=gce();<br>
// background setting<br>
if (~isnan(background)) then<br>
// optional background specified<br>
epoly.background=background;<br>
else<br>
// default background<br>
epoly.background=color("<u></u>gray87");<br>
end<br>
// foreground setting (as for background)<br>
if (~isnan(foreground)) then<br>
epoly.foreground=foreground;<br>
ey1.children.foreground=<u></u>foreground;<br>
ey2.children.foreground=<u></u>foreground;<br>
else<br>
epoly.foreground=color("<u></u>gray65");<br>
ey1.children.foreground=color(<u></u>"gray65");<br>
ey2.children.foreground=color(<u></u>"gray65");<br>
end<br>
endfunction<br>
//////////////////////////////<u></u>//////////////////////////////<u></u>//////////////////////////////<u></u>//////////////////////////////<u></u>//////<br>
<br>
It's far from perfect but it does what I need.<br>
Hope it helps,<br><font color="#888888">
<br>
Antoine<br>
</font></blockquote></div><br><br clear="all"><div><br></div>-- <br>Sumit Adhikari,<br>Institute of Computer Technology,<br>Faculty of Electrical Engineering,<br>Vienna University of Technology,<br>Gußhausstraße 27-29,1040 Vienna<br>
</div>