[scilab-Users] Equivalent of matlab area plot
Antoine Monmayrant
antoine.monmayrant at laas.fr
Fri Jan 21 13:56:28 CET 2011
Le 21/01/2011 13:44, Ruben Bibas a écrit :
> Hi everyone,
>
> I am currently trying to convert my matlab code to Scilab that was area plots.
> Is there an equivalent in Scilab?
> Any comments are appreciated, even just suggestions or websites that
> can help are also appreciated.
>
> Thank you
Hi,
I was looking for the same a year ago and found nothing.
So I quickly put together the function below to fill the area between
two curves.
It is not exactly what you are looking for, but maybe it can help you
hack your own solution.
Antoine
// Plot area between two curves
function [h,epoly,ey1,ey2]=BetweenCurves(x,y1,y2,varargin)
//
// Plots two curves and fill the area in between
//
// INPUTS:
// x vector (1,n) of horizontal coordinates
// y1 vector (1,n) value of 1st curve y1(x)
// y2 vector (1,n) value of 2nd curve y2(x)
// -- optional inputs: pairs "keyword","value" --
// "handle",h handle to the graphic window to use
// "axis",a handle to the graphic axis to use
// "foreground", colorid id of the color to use for
painting the area
// "background", colorid id of the color to use for
curves stroke
//
// OUTPUTS:
// h handle to the graphic window used
// epoly handle to the polygon that fill the area in between
// ey1 handle to first curve
// ey2 handle to second curve
//default values for optional argument
hfig=-1;
background=%nan;
foreground=%nan;
// scan varargin for optional parameter pairs (they can appear in any order)
for i=1:2:length(varargin)
keyword=varargin(i);
value=varargin(i+1);
select keyword
case "handle" then
hfig=value;
scf(hfig);
case "axis" then
axis=value;
sca(axis);
hfig=axis.parent;
case "background" then
background=value;
case "foreground" then
background=value;
end
end
// special treatment for handle (aka hack alert)
if typeof(hfig) ~= "handle" then
hfig=scf();
end
h=hfig;
scf(hfig);
xfpoly([x,x($:-1:1)],[y1,y2($:-1:1)]);
epoly=gce();
plot(x,y1);
ey1=gce();
plot(x,y2);
ey2=gce();
// background setting
if (~isnan(background)) then
// optional background specified
epoly.background=background;
else
// default background
epoly.background=color("gray87");
end
// foreground setting (as for background)
if (~isnan(foreground)) then
epoly.foreground=foreground;
ey1.children.foreground=foreground;
ey2.children.foreground=foreground;
else
epoly.foreground=color("gray65");
ey1.children.foreground=color("gray65");
ey2.children.foreground=color("gray65");
end
endfunction
More information about the users
mailing list