1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 // Copyright (C) DIGITEO - 2012 - Allan CORNET
4 // Copyright (C) 2012 - 2016 - Scilab Enterprises
6 // This file is hereby licensed under the terms of the GNU GPL v2.0,
7 // pursuant to article 5.3.4 of the CeCILL v.2.1.
8 // This file was originally licensed under the terms of the CeCILL v2.1,
9 // and continues to be available under such terms.
10 // For more information, see the COPYING file which you should have received
11 // along with this program.
13 function contourf(x, y, z, nv, style, strf, leg, rect, nax)
15 [nout, nin] = argn(0);
17 if nin == 0 then // demo
31 z=rand(size(x,"*"), size(y,"*"));
36 nv = zmin + (1:10) * (zmax-zmin)/(11);
58 error(msprintf(gettext("%s: Wrong type for input argument #%d: Real vector expected.\n"), "contourf", 1));
62 error(msprintf(gettext("%s: Wrong type for input argument #%d: Real vector expected.\n"), "contourf", 2));
66 error(msprintf(gettext("%s: Wrong type for input argument #%d: Real matrix expected.\n"), "contourf", 3));
70 error(msprintf(gettext("%s: Wrong type for input argument #%d: Real matrix expected.\n"), "contourf", 4));
73 if type(strf) <> 10 then
74 error(msprintf(gettext("%s: Wrong type for input argument #%d: String expected.\n"), "contourf", 6));
77 if type(leg) <> 10 then
78 error(msprintf(gettext("%s: Wrong type for input argument #%d: String expected.\n"), "contourf", 7));
81 if type(rect) <> 1 then
82 error(msprintf(gettext("%s: Wrong type for input argument #%d: Real matrix expected.\n"), "contourf", 8));
85 if type(nax) <> 1 then
86 error(msprintf(gettext("%s: Wrong type for input argument #%d: Real matrix expected.\n"), "contourf", 9));
95 nv = zmin + (1:nvs)*(zmax-zmin)/(nvs+1);
99 style = -1*ones(1, nvs);
102 if type(style) <> 1 then
103 error(msprintf(gettext("%s: Wrong type for input argument #%d: Real matrix expected.\n"), "contourf", 5));
107 rect=[min(x), min(y), max(x), max(y)];
111 error(msprintf(gettext("%s: Wrong size for input argument #%d: Real vector expected.\n"), "contourf", 1));
115 error(msprintf(gettext("%s: Wrong size for input argument #%d: Real vector expected.\n"), "contourf", 2));
118 if size(strf, "*") <> 1 then
119 error(msprintf(gettext("%s: Wrong size for input argument #%d: string expected.\n"), "contourf", 6));
122 if size(leg, "*") <> 1 then
123 error(msprintf(gettext("%s: Wrong size for input argument #%d: string expected.\n"), "contourf", 7));
131 // Surround the matrix by a very low region to get closed contours, and
132 // replace any NaN with low numbers as well.
133 zz=[ %nan * ones(1,nz+2) + %nan;
134 %nan * ones(mz,1) + %nan, z, %nan * ones(mz,1) + %nan;
135 %nan * ones(1,nz+2) + %nan];
137 kk=find(isnan(zz(:)));
139 zz(kk)=minz-1e4*(maxz-minz)+zeros(kk);
141 xx = [2 * x(1) - x(2); x(:); 2 * x(mz) - x(mz - 1)];
142 yy = [2 * y(1) - y(2); y(:); 2 * y(nz) - y(nz - 1)];
144 // Internal call to get the contours
145 [x1,y1]=contour2di(xx,yy,zz,nv);
147 // Find the indices of the curves in the c matrix, and get the
148 // area of closed curves in order to draw patches correctly.
154 while (ii < size(CS,2)),
156 ncurves = ncurves + 1;
158 xp=CS(1,ii+(1:nl)); // First patch
160 Area(ncurves)=sum(diff(xp).*(yp(1:nl-1)+yp(2:nl))/2);
164 lp = size(gcf().color_map, 1);
166 if size(nv,"*") > 1 // case where nv is a vector defining the level curve values
168 error(msprintf(gettext("%s: Colormap too small"),"contourf"));
172 error(msprintf(gettext("%s: Colormap too small"),"contourf"));
180 initDrawingMode = gcf().immediate_drawing;
181 gcf().immediate_drawing = "off";
183 plot2d([min(xx);max(xx)],[min(yy);max(yy)],0,strf,leg,rect,nax);
185 // Plot patches in order of decreasing size. This makes sure that
186 // all the lev1es get drawn, not matter if we are going up a hill or
187 // down into a hole. When going down we shift levels though, you can
188 // tell whether we are going up or down by checking the sign of the
189 // area (since curves are oriented so that the high side is always
190 // the same side). Lowest curve is largest and encloses higher data
195 [FA,IA]=gsort(abs(Area));
198 old_foreground = ax.foreground;
199 pat = old_foreground;
203 if (lev1 ~= minz | draw_min) then
204 xp=CS(1,I(jj)+(1:nl));
205 yp=CS(2,I(jj)+(1:nl));
206 pat = size(find( nv <= lev1),"*");
213 contour2d(xx,yy,zz,nv,style,"000",leg,rect,nax);
215 ax.foreground = old_foreground;
217 gcf().immediate_drawing = initDrawingMode;