1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 // This file must be used under the terms of the CeCILL.
4 // This source file is licensed as described in the file COPYING, which
5 // you should have received as part of this distribution. The terms
6 // are also available at
7 // http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
9 function contourf(x,y,z,nv,style,strf,leg,rect,nax)
13 if nin == 0 then // demo
20 if nin <= 0 then x=1:10;end
21 if nin <= 1 then y=1:10;end
22 if nin <= 2 then z=rand(size(x,'*'),size(y,'*'));end
23 if nin <= 3 then zmin=mini(z);zmax=maxi(z);nv = zmin + (1:10)*(zmax-zmin)/(11);end
24 if nin <= 5 then strf="121";end
25 if nin <= 6 then leg=" ";end
26 if nin <= 7 then rect=[0,0,1,1];end
27 if nin <= 8 then nax=[1,10,1,10];end
28 if x==[] then x=1:size(z,'r');end
29 if y==[] then y=1:size(z,'c');end
32 if nvs==1 then nvs=nv;zmin=mini(z);zmax=maxi(z);nv = zmin + (1:nvs)*(zmax-zmin)/(nvs+1);end;
33 if nin <= 4 then style = -1*ones(1,nvs);end
34 if nin <= 7 then rect=[mini(x),mini(y),maxi(x),maxi(y)]; end
39 // Surround the matrix by a very low region to get closed contours, and
40 // replace any NaN with low numbers as well.
41 zz=[ %nan*ones(1,nz+2); %nan*ones(mz,1),z,%nan*ones(mz,1);%nan*ones(1,nz+2)];
42 kk=find(isnan(zz(:)));
43 zz(kk)=minz-1e4*(maxz-minz)+zeros(kk);
45 xx = [2*x(1)-x(2); x(:); 2*x(mz)-x(mz-1)];
46 yy = [2*y(1)-y(2); y(:); 2*y(nz)-y(nz-1)];
48 // Internal call to get the contours
49 [x1,y1]=contour2di(xx,yy,zz,nv);
51 // Find the indices of the curves in the c matrix, and get the
52 // area of closed curves in order to draw patches correctly.
58 while (ii < size(CS,2)),
60 ncurves = ncurves + 1;
62 xp=CS(1,ii+(1:nl)); // First patch
64 Area(ncurves)=sum( mtlb_diff(xp).*(yp(1:nl-1)+yp(2:nl))/2 );
68 lp=xget('lastpattern');
70 if size(nv,'*') > 1 // case where nv is a vector defining the level curve values
71 if size(nv,'*') > lp ; write(%io(2),'Colormap too small');return ;end
73 if nv > lp ; write(%io(2),'Colormap too small');return ;end
79 plot2d([mini(xx);maxi(xx)],[mini(yy);maxi(yy)],0,strf,leg,rect,nax);
81 // Plot patches in order of decreasing size. This makes sure that
82 // all the lev1es get drawn, not matter if we are going up a hill or
83 // down into a hole. When going down we shift levels though, you can
84 // tell whether we are going up or down by checking the sign of the
85 // area (since curves are oriented so that the high side is always
86 // the same side). Lowest curve is largest and encloses higher data
91 [FA,IA]=sort(abs(Area));
93 drawlater(); // postpon the drawing here
95 old_foreground = a.foreground;
100 if (lev1 ~= minz | draw_min),
101 xp=CS(1,I(jj)+(1:nl));
102 yp=CS(2,I(jj)+(1:nl));
103 pat=size(find( nv <= lev1),'*');
110 contour2d(xx,yy,zz,nv,style,"000",leg,rect,nax);
112 a.foreground = old_foreground;
113 drawnow(); // draw all now!