Mesh plot demo

Image obtained by using color PostScript driver (psc) and then converted to animated gif using ImageMagick convert tool.

  1 #pragma _ipath "./"
  2 #include "plcdemos.h"
  3 
  4 #define XPTS    35		/* Data points in x */
  5 #define YPTS    46		/* Data points in y */
  6 #define LEVELS 10 
  7 
  8 static int opt[] = { DRAW_LINEXY, DRAW_LINEXY};
  9 
 10 static PLFLT alt[] = {33.0, 17.0};
 11 static PLFLT az[] = {24.0, 115.0};
 12 
 13 static char *title[4] =
 14 {
 15     "#frPLplot Example 11 - Alt=33, Az=24, Opt=3",
 16     "#frPLplot Example 11 - Alt=17, Az=115, Opt=3",
 17 };
 18 
 19 static void
 20 cmap1_init()
 21 {
 22   PLFLT i[2], h[2], l[2], s[2];
 23 
 24   i[0] = 0.0;		  i[1] = 1.0;		
 25   h[0] = 240;  h[1] = 0;
 26   l[0] = 0.6;
 27   l[1] = 0.6;
 28 
 29   s[0] = 0.8;
 30   s[1] = 0.8;
 31 
 32   plscmap1n(256);
 33   plscmap1l(0, 2, i, h, l, s, NULL);
 34 }
 35 
 36 
 37 int
 38 main(int argc, char *argv[])
 39 {
 40   int i, j, k;
 41   PLFLT *x, *y, **z;
 42   PLFLT xx, yy;
 43   int nlevel = LEVELS;
 44   PLFLT clevel[LEVELS];
 45   PLFLT zmin, zmax, step;
 46 
 47 
 48   (void) plParseOpts(&argc, argv, PL_PARSE_FULL);
 49 
 50 
 51   plinit();
 52 
 53   x = (PLFLT *) calloc(XPTS, sizeof(PLFLT));
 54   y = (PLFLT *) calloc(YPTS, sizeof(PLFLT));
 55 
 56   plAlloc2dGrid(&z, XPTS, YPTS);
 57   for (i = 0; i < XPTS; i++) {
 58     x[i] = 3. * (double) (i - (XPTS / 2)) / (double) (XPTS / 2);
 59   }
 60 
 61   for (i = 0; i < YPTS; i++)
 62     y[i] = 3.* (double) (i - (YPTS / 2)) / (double) (YPTS / 2);
 63 
 64   for (i = 0; i < XPTS; i++) {
 65     xx = x[i];
 66     for (j = 0; j < YPTS; j++) {
 67       yy = y[j];
 68       z[i][j] = 3. * (1.-xx)*(1.-xx) * exp(-(xx*xx) - (yy+1.)*(yy+1.)) -
 69 	10. * (xx/5. - pow(xx,3.) - pow(yy,5.)) * exp(-xx*xx-yy*yy) -
 70 	1./3. * exp(-(xx+1)*(xx+1) - (yy*yy));
 71 		 
 72       if(0) {	if (z[i][j] < -1.)
 73 	  z[i][j] = -1.;
 74       }
 75     }
 76   }
 77 
 78   plMinMax2dGrid(z, XPTS, YPTS, &zmax, &zmin);  
 79   step = (zmax - zmin)/(nlevel+1);
 80   for (i=0; i<nlevel; i++)
 81     clevel[i] = zmin + step + step*i;
 82 
 83   cmap1_init();
 84   for (k = 0; k < 2; k++) {
 85     for (i=0; i<4; i++) {
 86       pladv(0);
 87       plcol0(1);
 88       plvpor(0.0, 1.0, 0.0, 0.9);
 89       plwind(-1.0, 1.0, -1.0, 1.5);
 90       plw3d(1.0, 1.0, 1.2, -3.0, 3.0, -3.0, 3.0, zmin, zmax, alt[k], az[k]);
 91       plbox3("bnstu", "x axis", 0.0, 0,
 92 	     "bnstu", "y axis", 0.0, 0,
 93 	     "bcdmnstuv", "z axis", 0.0, 4);
 94 
 95       plcol0(2);
 96 
 97       if (i==0)
 98 	plmesh(x, y, z, XPTS, YPTS, opt[k]);
 99 
100       else if (i==1)
101 	plmesh(x, y, z, XPTS, YPTS, opt[k] | MAG_COLOR);
102 
103       else if (i==2)
104 	plot3d(x, y, z, XPTS, YPTS, opt[k] | MAG_COLOR, 1);
105 
106       else if (i==3)
107 	plmeshc(x, y, z, XPTS, YPTS, opt[k] | MAG_COLOR | BASE_CONT,
108 		clevel, nlevel);
109 
110       plcol0(3);
111       plmtex("t", 1.0, 0.5, 0.5, title[k]);
112     }
113   }
114 
115   
116   free((void *) x);
117   free((void *) y);
118   plFree2dGrid(z, XPTS, YPTS);
119 
120   plend();
121 
122   exit(0);
123 }

Copyright 2006 Roman Putanowicz

Email: putanowr at twins.pk.edu.pl

Last Modified: Thu, 13 Jul 2006 15:37:12 CEST

Made with PubTal 3.1.3