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 7 static PLFLT alt[] = {60.0, 20.0}; 8 static PLFLT az[] = {30.0, 60.0}; 9 static void cmap1_init(int); 10 11 static char *title[] = 12 { 13 "#frPLplot Example 8 - Alt=60, Az=30", 14 "#frPLplot Example 8 - Alt=20, Az=60", 15 }; 16 17 18 static void 19 cmap1_init(int gray) 20 { 21 PLFLT i[2], h[2], l[2], s[2]; 22 23 i[0] = 0.0; i[1] = 1.0; 24 if (gray) { 25 h[0] = 0.0; h[1] = 0.0; 26 l[0] = 0.5; l[1] = 1.0; 27 s[0] = 0.0; s[1] = 0.0; } else { 28 h[0] = 240; h[1] = 0; 29 l[0] = 0.6; 30 l[1] = 0.6; 31 32 s[0] = 0.8; 33 s[1] = 0.8; 34 } 35 36 plscmap1n(256); 37 plscmap1l(0, 2, i, h, l, s, NULL); 38 } 39 40 41 42 static int sombrero; 43 44 #define LEVELS 10 45 46 int 47 main(int argc, char *argv[]) 48 { 49 int i, j, k; 50 PLFLT *x, *y, **z; 51 PLFLT xx, yy, r; 52 PLINT ifshade; 53 PLFLT zmin, zmax, step; 54 PLFLT clevel[LEVELS]; 55 PLINT nlevel=LEVELS; 56 int rosen=1; 57 58 (void) plParseOpts(&argc, argv, PL_PARSE_FULL); 59 if (sombrero) 60 rosen=0; 61 62 63 plinit(); 64 65 66 x = (PLFLT *) calloc(XPTS, sizeof(PLFLT)); 67 y = (PLFLT *) calloc(YPTS, sizeof(PLFLT)); 68 69 plAlloc2dGrid(&z, XPTS, YPTS); 70 71 for (i = 0; i < XPTS; i++) { 72 x[i] = ((double) (i - (XPTS / 2)) / (double) (XPTS / 2)); 73 if (rosen) 74 x[i] *= 1.5; 75 } 76 77 for (i = 0; i < YPTS; i++) { 78 y[i] = (double) (i - (YPTS / 2)) / (double) (YPTS / 2); 79 if (rosen) 80 y[i] += 0.5; 81 } 82 83 for (i = 0; i < XPTS; i++) { 84 xx = x[i]; 85 for (j = 0; j < YPTS; j++) { 86 yy = y[j]; 87 if (rosen) { 88 z[i][j] = pow(1. - xx, 2.) + 100. * pow(yy - pow(xx, 2.), 2.); 89 if (z[i][j] > 0.) 90 z[i][j] = log(z[i][j]); 91 else 92 z[i][j] = -5.; } 93 else { 94 r = sqrt(xx * xx + yy * yy); 95 z[i][j] = exp(-r * r) * cos(2.0 * PI * r); 96 } 97 } 98 } 99 100 plMinMax2dGrid(z, XPTS, YPTS, &zmax, &zmin); 101 step = (zmax-zmin)/(nlevel+1); 102 for (i=0; i<nlevel; i++) 103 clevel[i] = zmin + step + step*i; 104 105 pllightsource(1.,1.,1.); 106 107 for (k = 0; k < 2; k++) { 108 for (ifshade = 0; ifshade < 4; ifshade++) { 109 pladv(0); 110 plvpor(0.0, 1.0, 0.0, 0.9); 111 plwind(-1.0, 1.0, -0.9, 1.1); 112 plcol0(3); 113 plmtex("t", 1.0, 0.5, 0.5, title[k]); 114 plcol0(1); 115 if (rosen) 116 plw3d(1.0, 1.0, 1.0, -1.5, 1.5, -0.5, 1.5, zmin, zmax, alt[k], az[k]); 117 else 118 plw3d(1.0, 1.0, 1.0, -1.0, 1.0, -1.0, 1.0, zmin, zmax, alt[k], az[k]); 119 120 plbox3("bnstu", "x axis", 0.0, 0, 121 "bnstu", "y axis", 0.0, 0, 122 "bcdmnstuv", "z axis", 0.0, 0); 123 plcol0(2); 124 125 if (ifshade == 0) { cmap1_init(1); 126 plsurf3d(x, y, z, XPTS, YPTS, 0, NULL, 0); 127 } else if (ifshade == 1) { cmap1_init(0); 128 plsurf3d(x, y, z, XPTS, YPTS, MAG_COLOR, NULL, 0); 129 } else if (ifshade == 2) { plsurf3d(x, y, z, XPTS, YPTS, MAG_COLOR | 130 ++++FACETED, NULL, 0); 131 } else plsurf3d(x, y, z, XPTS, YPTS, MAG_COLOR | SURF_CONT | BASE_CONT, 132 ++++clevel, nlevel); 133 } 134 } 135 136 137 free((void *) x); 138 free((void *) y); 139 plFree2dGrid(z, XPTS, YPTS); 140 141 plend(); 142 143 exit(0); 144 }
Code description
- 1
- $Id: x08c.c,v 1.43 2004/06/14 21:51:54 rlaboiss Exp $ 3-d plot demo. Copyright (C) 2004 Alan W. Irwin Copyright (C) 2004 Rafael Laboissiere This file is part of PLplot. PLplot is free software; you can redistribute it and/or modify it under the terms of the GNU General Library Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. PLplot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with PLplot; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- 17
- --------------------------------------------------------------------------*\ * cmap1_init1 * * Initializes color map 1 in HLS space. * Basic grayscale variation from half-dark (which makes more interesting * looking plot compared to dark) to light. * An interesting variation on this: * s[1] = 1.0 \*--------------------------------------------------------------------------
- 23
- left boundary
- 23
- right boundary
- 25
- hue -- low: red (arbitrary if s=0)
- 25
- hue -- high: red (arbitrary if s=0)
- 26
- lightness -- low: half-dark
- 26
- lightness -- high: light
- 27
- minimum saturation
- 27
- minimum saturation
- 28
- blue -> green -> yellow ->
- 28
- -> red
- 40
- --------------------------------------------------------------------------*\ * main * * Does a series of 3-d plots for a given data set, with different * viewing options in each plot. \*--------------------------------------------------------------------------
- 58
- Parse and process command line arguments
- 62
- Initialize plplot
- 65
- Allocate data structures
- 89
- The log argument may be zero for just the right grid.
- 92
- -MAXFLOAT would mess-up up the scale
- 125
- diffuse light surface plot
- 127
- magnitude colored plot
- 129
- magnitude colored plot with faceted squares
- 130
- magnitude colored plot with contours
- 134
- Clean up