static void plot1( void ) { PLFLT shade_min, shade_max, sh_color; PLINT sh_cmap = 0, sh_width; PLINT min_color = 0, min_width = 0, max_color = 0, max_width = 0; pladv( 0 ); plvpor( 0.1, 0.9, 0.1, 0.9 ); plwind( -1.0, 1.0, -1.0, 1.0 ); /* Plot using identity transform */ shade_min = zmin + ( zmax - zmin ) * 0.4; shade_max = zmin + ( zmax - zmin ) * 0.6; sh_color = 7; sh_width = 2; min_color = 9; max_color = 2; min_width = 2; max_width = 2; plpsty( 8 ); plshade1( &z[0][0], XPTS, YPTS, NULL, -1., 1., -1., 1., shade_min, shade_max, sh_cmap, sh_color, sh_width, min_color, min_width, max_color, max_width, plfill, 1, NULL, NULL ); plcol0( 1 ); plbox( "bcnst", 0.0, 0, "bcnstv", 0.0, 0 ); plcol0( 2 ); pllab( "distance", "altitude", "Bogon flux" ); }
int plp_init(const char *driver, const char *_title, int _is_complex) { int i; if (2*NOF_INPUT_ITF > 1) { modinfo("Multiple signals are currently displayed in the same plot\n"); } plsdev(driver); plinit(); pladv(0); title = _title; is_complex = _is_complex; for (i=0;i<2*NOF_INPUT_ITF;i++) { legends[i] = (const char*) ""; } for (i=0;i<INPUT_MAX_SAMPLES;i++) { t[i] = i; } setup_legend(); xlabel = xlabel_def; ylabel = ylabel_def; plscol0a( 14, 0, 0, 0, 1); reset_axis(); return 0; }
static void plot3( void ) { static PLFLT xx[2][5] = { { -1.0, 1.0, 1.0, -1.0, -1.0 }, { -1.0, 1.0, 1.0, -1.0, -1.0 } }; static PLFLT yy[2][5] = { { 1.0, 1.0, 0.0, 0.0, 1.0 }, { -1.0, -1.0, 0.0, 0.0, -1.0 } }; static PLFLT zz[2][5] = { { 0.0, 0.0, 1.0, 1.0, 0.0 }, { 0.0, 0.0, 1.0, 1.0, 0.0 } }; pladv( 0 ); plvpor( 0.1, 0.9, 0.1, 0.9 ); plwind( -1.0, 1.0, -1.0, 1.0 ); plw3d( 1., 1., 1., -1.0, 1.0, -1.0, 1.0, 0.0, 1.5, 30, -40 ); /* Plot using identity transform */ plcol0( 1 ); plbox3( "bntu", "X", 0.0, 0, "bntu", "Y", 0.0, 0, "bcdfntu", "Z", 0.5, 0 ); plcol0( 2 ); pllab( "", "", "3-d polygon filling" ); plcol0( 3 ); plpsty( 1 ); plline3( 5, xx[0], yy[0], zz[0] ); plfill3( 4, xx[0], yy[0], zz[0] ); plpsty( 2 ); plline3( 5, xx[1], yy[1], zz[1] ); plfill3( 4, xx[1], yy[1], zz[1] ); }
int main(int argc, char *argv[]) { char text[10]; int i, j, k; PLFLT x, y; /* Parse and process command line arguments */ (void) plparseopts(&argc, argv, PL_PARSE_FULL); /* Initialize plplot */ plinit(); pladv(0); /* Set up viewport and window */ plcol0(2); plvpor(0.1, 1.0, 0.1, 0.9); plwind(0.0, 1.0, 0.0, 1.3); /* Draw the grid using plbox */ plbox("bcg", 0.1, 0, "bcg", 0.1, 0); /* Write the digits below the frame */ plcol0(15); for (i = 0; i <= 9; i++) { sprintf(text, "%d", i); plmtex("b", 1.5, (0.1 * i + 0.05), 0.5, text); } k = 0; for (i = 0; i <= 12; i++) { /* Write the digits to the left of the frame */ sprintf(text, "%d", 10 * i); plmtex("lv", 1.0, (1.0 - (2 * i + 1) / 26.0), 1.0, text); for (j = 0; j <= 9; j++) { x = 0.1 * j + 0.05; y = 1.25 - 0.1 * i; /* Display the symbols (plpoin expects that x and y are arrays so */ /* pass pointers) */ if (k < 128) plpoin(1, &x, &y, k); k = k + 1; } } plmtex("t", 1.5, 0.5, 0.5, "PLplot Example 6 - plpoin symbols"); plend(); exit(0); }
PlPlotWidget::PlPlotWidget(QWidget *parent) : QWidget(parent) { setAttribute( Qt::WA_DeleteOnClose ); plot = new QtExtWidget( parent->width(), parent->height(), parent ); //this should fit the widget box plmkstrm( &strm );// One window = One plot widget = one stream plsdev( "extqt" ); plsetqtdev( plot ); plinit(); plot->setBackgroundColor(255,255,255,1); //resize( 400, 320 ); pladv( 0 ); unsigned int col = 255; plscolbg(col,col,col); }
static void plot2( void ) { PLFLT shade_min, shade_max, sh_color; PLINT sh_cmap = 0, sh_width; PLINT min_color = 0, min_width = 0, max_color = 0, max_width = 0; int i; static PLINT nlin[10] = { 1, 1, 1, 1, 1, 2, 2, 2, 2, 2 }; static PLINT inc[10][2] = { { 450, 0 }, { -450, 0 }, { 0, 0 }, { 900, 0 }, { 300, 0 }, { 450, -450 }, { 0, 900 }, { 0, 450 }, { 450, -450 }, { 0, 900 } }; static PLINT del[10][2] = { { 2000, 2000 }, { 2000, 2000 }, { 2000, 2000 }, { 2000, 2000 }, { 2000, 2000 }, { 2000, 2000 }, { 2000, 2000 }, { 2000, 2000 }, { 4000, 4000 }, { 4000, 2000 } }; sh_width = 2; pladv( 0 ); plvpor( 0.1, 0.9, 0.1, 0.9 ); plwind( -1.0, 1.0, -1.0, 1.0 ); /* Plot using identity transform */ for ( i = 0; i < 10; i++ ) { shade_min = zmin + ( zmax - zmin ) * i / 10.0; shade_max = zmin + ( zmax - zmin ) * ( i + 1 ) / 10.0; sh_color = i + 6; plpat( nlin[i], inc[i], del[i] ); plshade1( &z[0][0], XPTS, YPTS, NULL, -1., 1., -1., 1., shade_min, shade_max, sh_cmap, sh_color, sh_width, min_color, min_width, max_color, max_width, plfill, 1, NULL, NULL ); } plcol0( 1 ); plbox( "bcnst", 0.0, 0, "bcnstv", 0.0, 0 ); plcol0( 2 ); pllab( "distance", "altitude", "Bogon flux" ); }
void plot3( void ) { PLINT space0 = 0, mark0 = 0, space1 = 1500, mark1 = 1500; int i; // For the final graph we wish to override the default tick intervals, and // so do not use plenv(). // pladv( 0 ); // Use standard viewport, and define X range from 0 to 360 degrees, Y range // from -1.2 to 1.2. // plvsta(); plwind( 0.0, 360.0, -1.2, 1.2 ); // Draw a box with ticks spaced 60 degrees apart in X, and 0.2 in Y. plcol0( 1 ); plbox( "bcnst", 60.0, 2, "bcnstv", 0.2, 2 ); // Superimpose a dashed line grid, with 1.5 mm marks and spaces. // plstyl expects a pointer! // plstyl( 1, &mark1, &space1 ); plcol0( 2 ); plbox( "g", 30.0, 0, "g", 0.2, 0 ); plstyl( 0, &mark0, &space0 ); plcol0( 3 ); pllab( "Angle (degrees)", "sine", "#frPLplot Example 1 - Sine function" ); for ( i = 0; i < 101; i++ ) { x[i] = 3.6 * i; y[i] = sin( x[i] * M_PI / 180.0 ); } plcol0( 4 ); plline( 101, x, y ); }
void plot3( void ) { int i; // For the final graph we wish to override the default tick intervals, and // so do not use PLENV pladv( 0 ); // Use standard viewport, and define X range from 0 to 360 degrees, Y range // from -1.2 to 1.2. plvsta(); plwind( (PLFLT) 0.0, (PLFLT) 360.0, (PLFLT) -1.2, (PLFLT) 1.2 ); // Draw a box with ticks spaced 60 degrees apart in X, and 0.2 in Y. plcol0( 1 ); plbox( "bcnst", (PLFLT) 60.0, 2, "bcnstv", (PLFLT) 0.2, 2 ); // Superimpose a dashed line grid, with 1.5 mm marks and spaces. plstyl // expects a pointer!! plstyl( 1, &mark1, &space1 ); plcol0( 2 ); plbox( "g", (PLFLT) 30.0, 0, "g", (PLFLT) 0.2, 0 ); plstyl( 0, &mark0, &space0 ); plcol0( 3 ); pllab( "Angle (degrees)", "sine", "#frPLplot Example 1 - Sine function" ); for ( i = 0; i < 101; i++ ) { x[i] = 3.6 * i; y[i] = sin( x[i] * 3.141592654 / 180.0 ); } plcol0( 4 ); plline( 101, x, y ); }
static void plplot_set_window_size( plot_driver_type * driver , int width , int height) { char * geometry = util_alloc_sprintf("%dx%d", width, height); plsetopt("geometry", geometry); free( geometry ); { plplot_state_type * state = driver->state; plsstrm( state->stream ); //{ // printf("---------- Calling plinit()\n"); // errno = 0; // pllib_init(); // printf("%s: after plinit(): errno:%d / strerror:%s\n",__func__ , errno , strerror( errno )); //} plinit(); pladv(0); /* And what does this do ... */ plvsta(); } }
int main( int argc, char *argv[] ) { int i, j; plparseopts( &argc, argv, PL_PARSE_FULL ); plinit(); pladv( 0 ); plvpor( 0.0, 1.0, 0.0, 1.0 ); plwind( 0.0, 1.0, 0.0, 1.0 ); plcol0( 0 ); plbox( "", 1.0, 0, "", 1.0, 0 ); plscmap0n( 7 ); plscmap0( red, green, blue, 7 ); plschr( 0, 4.0 ); plfont( 1 ); for ( i = 0; i < 4; i++ ) { plcol0( i + 1 ); plfill( 4, px, py ); for ( j = 0; j < 4; j++ ) py [j] += 1.0 / 4.0; } plcol0( 0 ); for ( i = 0; i < 12; i++ ) plptex( sx [i], sy [i], 1.0, 0.0, 0.5, peace [i] ); plend(); exit( 0 ); }
int main( int argc, const char *argv[] ) { /* Parse and process command line arguments */ (void) plparseopts( &argc, argv, PL_PARSE_FULL ); /* Initialize plplot */ plinit(); pladv( 0 ); plvpor( 0.0, 1.0, 0.0, 1.0 ); plwind( 0.0, 1.0, 0.0, 1.0 ); plbox( "bc", 0.0, 0, "bc", 0.0, 0 ); plsvpa( 50.0, 150.0, 50.0, 100.0 ); plwind( 0.0, 1.0, 0.0, 1.0 ); plbox( "bc", 0.0, 0, "bc", 0.0, 0 ); plptex( 0.5, 0.5, 1.0, 0.0, 0.5, "BOX at (50,150,50,100)" ); plend(); exit( 0 ); }
int main( int argc, char *argv[] ) { PLFLT xmin0, xmax0, ymin0, ymax0, zxmin0, zxmax0, zymin0, zymax0; PLFLT xmin, xmax, ymin, ymax, zxmin, zxmax, zymin, zymax; PLFLT xmid, ymid, wx, wy; PLFLT mar0, aspect0, jx0, jy0, ori0; PLFLT mar, aspect, jx, jy, ori; PLINT win, level2, digmax, digits, compression1, compression2; PLFLT xp0, yp0; PLINT xleng0, yleng0, xoff0, yoff0; PLFLT xp1, yp1; PLINT xleng1, yleng1, xoff1, yoff1; PLFLT xp2, yp2; PLINT xleng2, yleng2, xoff2, yoff2; PLINT fam0, num0, bmax0; PLINT fam1, num1, bmax1; PLINT fam2, num2, bmax2; PLINT r0, g0, b0; PLFLT a0; PLINT r, g, b; PLFLT a; PLINT r1[] = { 0, 255 }; PLINT g1[] = { 255, 0 }; PLINT b1[] = { 0, 0 }; PLFLT a1[] = { 1.0, 1.0 }; int status; char fnam[256]; // Parse and process command line arguments status = 0; (void) plparseopts( &argc, argv, PL_PARSE_FULL ); // Test setting / getting familying parameters before plinit // Save values set by plparseopts to be restored later. plgfam( &fam0, &num0, &bmax0 ); fam1 = 0; num1 = 10; bmax1 = 1000; plsfam( fam1, num1, bmax1 ); // Retrieve the same values? plgfam( &fam2, &num2, &bmax2 ); printf( "family parameters: fam, num, bmax = %d %d %d\n", fam2, num2, bmax2 ); if ( fam2 != fam1 || num2 != num1 || bmax2 != bmax1 ) { fputs( "plgfam test failed\n", stderr ); status = 1; } // Restore values set initially by plparseopts. plsfam( fam0, num0, bmax0 ); // Test setting / getting page parameters before plinit // Save values set by plparseopts to be restored later. plgpage( &xp0, &yp0, &xleng0, &yleng0, &xoff0, &yoff0 ); xp1 = 200.; yp1 = 200.; xleng1 = 400; yleng1 = 200; xoff1 = 10; yoff1 = 20; plspage( xp1, yp1, xleng1, yleng1, xoff1, yoff1 ); // Retrieve the same values? plgpage( &xp2, &yp2, &xleng2, &yleng2, &xoff2, &yoff2 ); printf( "page parameters: xp, yp, xleng, yleng, xoff, yoff = %f %f %d %d %d %d\n", xp2, yp2, xleng2, yleng2, xoff2, yoff2 ); if ( xp2 != xp1 || yp2 != yp1 || xleng2 != xleng1 || yleng2 != yleng1 || xoff2 != xoff1 || yoff2 != yoff1 ) { fputs( "plgpage test failed\n", stderr ); status = 1; } // Restore values set initially by plparseopts. plspage( xp0, yp0, xleng0, yleng0, xoff0, yoff0 ); // Test setting / getting compression parameter across plinit. compression1 = 95; plscompression( compression1 ); // Initialize plplot plinit(); // Test if device initialization screwed around with the preset // compression parameter. plgcompression( &compression2 ); printf( "Output various PLplot parameters\n" ); printf( "compression parameter = %d\n", compression2 ); if ( compression2 != compression1 ) { fputs( "plgcompression test failed\n", stderr ); status = 1; } // Exercise plscolor, plscol0, plscmap1, and plscmap1a to make sure // they work without any obvious error messages. plscolor( 1 ); plscol0( 1, 255, 0, 0 ); plscmap1( r1, g1, b1, 2 ); plscmap1a( r1, g1, b1, a1, 2 ); plglevel( &level2 ); printf( "level parameter = %d\n", level2 ); if ( level2 != 1 ) { fputs( "plglevel test failed.\n", stderr ); status = 1; } pladv( 0 ); xmin0 = 0.01; xmax0 = 0.99; ymin0 = 0.02; ymax0 = 0.49; plvpor( xmin0, xmax0, ymin0, ymax0 ); plgvpd( &xmin, &xmax, &ymin, &ymax ); printf( "plvpor: xmin, xmax, ymin, ymax = %f %f %f %f\n", xmin, xmax, ymin, ymax ); if ( xmin != xmin0 || xmax != xmax0 || ymin != ymin0 || ymax != ymax0 ) { fputs( "plgvpd test failed\n", stderr ); status = 1; } xmid = 0.5 * ( xmin + xmax ); ymid = 0.5 * ( ymin + ymax ); xmin0 = 0.2; xmax0 = 0.3; ymin0 = 0.4; ymax0 = 0.5; plwind( xmin0, xmax0, ymin0, ymax0 ); plgvpw( &xmin, &xmax, &ymin, &ymax ); printf( "plwind: xmin, xmax, ymin, ymax = %f %f %f %f\n", xmin, xmax, ymin, ymax ); if ( xmin != xmin0 || xmax != xmax0 || ymin != ymin0 || ymax != ymax0 ) { fputs( "plgvpw test failed\n", stderr ); status = 1; } // Get world coordinates for middle of viewport plcalc_world( xmid, ymid, &wx, &wy, &win ); printf( "world parameters: wx, wy, win = %f %f %d\n", wx, wy, win ); if ( fabs( wx - 0.5 * ( xmin + xmax ) ) > 1.0E-5 || fabs( wy - 0.5 * ( ymin + ymax ) ) > 1.0E-5 ) { fputs( "plcalc_world test failed\n", stderr ); status = 1; } // Retrieve and print the name of the output file (if any). // This goes to stderr not stdout since it will vary between tests and // we want stdout to be identical for compare test. plgfnam( fnam ); if ( fnam[0] == '\0' ) { printf( "No output file name is set\n" ); } else { printf( "Output file name read\n" ); } fprintf( stderr, "Output file name is %s\n", fnam ); // Set and get the number of digits used to display axis labels // Note digits is currently ignored in pls[xyz]ax and // therefore it does not make sense to test the returned // value plsxax( 3, 0 ); plgxax( &digmax, &digits ); printf( "x axis parameters: digmax, digits = %d %d\n", digmax, digits ); if ( digmax != 3 ) { fputs( "plgxax test failed\n", stderr ); status = 1; } plsyax( 4, 0 ); plgyax( &digmax, &digits ); printf( "y axis parameters: digmax, digits = %d %d\n", digmax, digits ); if ( digmax != 4 ) { fputs( "plgyax test failed\n", stderr ); status = 1; } plszax( 5, 0 ); plgzax( &digmax, &digits ); printf( "z axis parameters: digmax, digits = %d %d\n", digmax, digits ); if ( digmax != 5 ) { fputs( "plgzax test failed\n", stderr ); status = 1; } mar0 = 0.05; aspect0 = PL_NOTSET; jx0 = 0.1; jy0 = 0.2; plsdidev( mar0, aspect0, jx0, jy0 ); plgdidev( &mar, &aspect, &jx, &jy ); printf( "device-space window parameters: mar, aspect, jx, jy = %f %f %f %f\n", mar, aspect, jx, jy ); if ( mar != mar0 || jx != jx0 || jy != jy0 ) { fputs( "plgdidev test failed\n", stderr ); status = 1; } ori0 = 1.0; plsdiori( ori0 ); plgdiori( &ori ); printf( "ori parameter = %f\n", ori ); if ( ori != ori0 ) { fputs( "plgdiori test failed\n", stderr ); status = 1; } xmin0 = 0.1; ymin0 = 0.2; xmax0 = 0.9; ymax0 = 0.8; plsdiplt( xmin0, ymin0, xmax0, ymax0 ); plgdiplt( &xmin, &ymin, &xmax, &ymax ); printf( "plot-space window parameters: xmin, ymin, xmax, ymax = %f %f %f %f\n", xmin, ymin, xmax, ymax ); if ( xmin != xmin0 || ymin != ymin0 || xmax != xmax0 || ymax != ymax0 ) { fputs( "plgdiplt test failed\n", stderr ); status = 1; } zxmin0 = 0.1; zymin0 = 0.1; zxmax0 = 0.9; zymax0 = 0.9; plsdiplz( zxmin0, zymin0, zxmax0, zymax0 ); plgdiplt( &zxmin, &zymin, &zxmax, &zymax ); printf( "zoomed plot-space window parameters: xmin, ymin, xmax, ymax = %f %f %f %f\n", zxmin, zymin, zxmax, zymax ); if ( fabs( zxmin - ( xmin + ( xmax - xmin ) * zxmin0 ) ) > 1.0E-5 || fabs( zymin - ( ymin + ( ymax - ymin ) * zymin0 ) ) > 1.0E-5 || fabs( zxmax - ( xmin + ( xmax - xmin ) * zxmax0 ) ) > 1.0E-5 || fabs( zymax - ( ymin + ( ymax - ymin ) * zymax0 ) ) > 1.0E-5 ) { fputs( "plsdiplz test failed\n", stderr ); status = 1; } r0 = 10; g0 = 20; b0 = 30; plscolbg( r0, g0, b0 ); plgcolbg( &r, &g, &b ); printf( "background colour parameters: r, g, b = %d %d %d\n", r, g, b ); if ( r != r0 || g != g0 || b != b0 ) { fputs( "plgcolbg test failed\n", stderr ); status = 1; } r0 = 20; g0 = 30; b0 = 40; a0 = 0.5; plscolbga( r0, g0, b0, a0 ); plgcolbga( &r, &g, &b, &a ); printf( "background/transparency colour parameters: r, g, b, a = %d %d %d %f\n", r, g, b, a ); if ( r != r0 || g != g0 || b != b0 || a != a0 ) { fputs( "plgcolbga test failed\n", stderr ); status = 1; } plend(); exit( status ); }
static void potential( void ) //shielded potential contour plot example. { int i, j; PLcGrid2 cgrid2; PLFLT rmax, xmin, xmax, x0, ymin, ymax, y0, zmin, zmax; PLFLT peps, xpmin, xpmax, ypmin, ypmax; PLFLT eps, q1, d1, q1i, d1i, q2, d2, q2i, d2i; PLFLT div1, div1i, div2, div2i; PLFLT **z; PLINT nlevelneg, nlevelpos; PLFLT dz, clevel2, clevelneg[PNLEVEL], clevelpos[PNLEVEL]; PLINT ncollin, ncolbox, ncollab; PLFLT px[PPERIMETERPTS], py[PPERIMETERPTS]; PLFLT t, r, theta; //create data to be contoured. plAlloc2dGrid( &cgrid2.xg, PRPTS, PTHETAPTS ); plAlloc2dGrid( &cgrid2.yg, PRPTS, PTHETAPTS ); plAlloc2dGrid( &z, PRPTS, PTHETAPTS ); cgrid2.nx = PRPTS; cgrid2.ny = PTHETAPTS; for ( i = 0; i < PRPTS; i++ ) { r = 0.5 + (double) i; for ( j = 0; j < PTHETAPTS; j++ ) { theta = ( 2. * M_PI / (double) ( PTHETAPTS - 1 ) ) * ( 0.5 + (double) j ); cgrid2.xg[i][j] = r * cos( theta ); cgrid2.yg[i][j] = r * sin( theta ); } } rmax = r; f2mnmx( cgrid2.xg, PRPTS, PTHETAPTS, &xmin, &xmax ); f2mnmx( cgrid2.yg, PRPTS, PTHETAPTS, &ymin, &ymax ); x0 = ( xmin + xmax ) / 2.; y0 = ( ymin + ymax ) / 2.; // Expanded limits peps = 0.05; xpmin = xmin - fabs( xmin ) * peps; xpmax = xmax + fabs( xmax ) * peps; ypmin = ymin - fabs( ymin ) * peps; ypmax = ymax + fabs( ymax ) * peps; // Potential inside a conducting cylinder (or sphere) by method of images. // Charge 1 is placed at (d1, d1), with image charge at (d2, d2). // Charge 2 is placed at (d1, -d1), with image charge at (d2, -d2). // Also put in smoothing term at small distances. // eps = 2.; q1 = 1.; d1 = rmax / 4.; q1i = -q1 * rmax / d1; d1i = pow( rmax, 2. ) / d1; q2 = -1.; d2 = rmax / 4.; q2i = -q2 * rmax / d2; d2i = pow( rmax, 2. ) / d2; for ( i = 0; i < PRPTS; i++ ) { for ( j = 0; j < PTHETAPTS; j++ ) { div1 = sqrt( pow( cgrid2.xg[i][j] - d1, 2. ) + pow( cgrid2.yg[i][j] - d1, 2. ) + pow( eps, 2. ) ); div1i = sqrt( pow( cgrid2.xg[i][j] - d1i, 2. ) + pow( cgrid2.yg[i][j] - d1i, 2. ) + pow( eps, 2. ) ); div2 = sqrt( pow( cgrid2.xg[i][j] - d2, 2. ) + pow( cgrid2.yg[i][j] + d2, 2. ) + pow( eps, 2. ) ); div2i = sqrt( pow( cgrid2.xg[i][j] - d2i, 2. ) + pow( cgrid2.yg[i][j] + d2i, 2. ) + pow( eps, 2. ) ); z[i][j] = q1 / div1 + q1i / div1i + q2 / div2 + q2i / div2i; } } f2mnmx( z, PRPTS, PTHETAPTS, &zmin, &zmax ); // printf("%.15g %.15g %.15g %.15g %.15g %.15g %.15g %.15g \n", // q1, d1, q1i, d1i, q2, d2, q2i, d2i); // printf("%.15g %.15g %.15g %.15g %.15g %.15g \n", // xmin, xmax, ymin, ymax, zmin, zmax); // Positive and negative contour levels. dz = ( zmax - zmin ) / (double) PNLEVEL; nlevelneg = 0; nlevelpos = 0; for ( i = 0; i < PNLEVEL; i++ ) { clevel2 = zmin + ( (double) i + 0.5 ) * dz; if ( clevel2 <= 0. ) clevelneg[nlevelneg++] = clevel2; else clevelpos[nlevelpos++] = clevel2; } // Colours! ncollin = 11; ncolbox = 1; ncollab = 2; // Finally start plotting this page! pladv( 0 ); plcol0( ncolbox ); plvpas( 0.1, 0.9, 0.1, 0.9, 1.0 ); plwind( xpmin, xpmax, ypmin, ypmax ); plbox( "", 0., 0, "", 0., 0 ); plcol0( ncollin ); if ( nlevelneg > 0 ) { // Negative contours pllsty( 2 ); plcont( (const PLFLT * const *) z, PRPTS, PTHETAPTS, 1, PRPTS, 1, PTHETAPTS, clevelneg, nlevelneg, pltr2, (void *) &cgrid2 ); } if ( nlevelpos > 0 ) { // Positive contours pllsty( 1 ); plcont( (const PLFLT * const *) z, PRPTS, PTHETAPTS, 1, PRPTS, 1, PTHETAPTS, clevelpos, nlevelpos, pltr2, (void *) &cgrid2 ); } // Draw outer boundary for ( i = 0; i < PPERIMETERPTS; i++ ) { t = ( 2. * M_PI / ( PPERIMETERPTS - 1 ) ) * (double) i; px[i] = x0 + rmax * cos( t ); py[i] = y0 + rmax * sin( t ); } plcol0( ncolbox ); plline( PPERIMETERPTS, px, py ); plcol0( ncollab ); pllab( "", "", "Shielded potential of charges in a conducting sphere" ); plFree2dGrid( z, PRPTS, PTHETAPTS ); plFree2dGrid( cgrid2.xg, PRPTS, PTHETAPTS ); plFree2dGrid( cgrid2.yg, PRPTS, PTHETAPTS ); }
static void c_plenvi(PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax, PLINT just, PLINT axis, PLINT old) { PLFLT lb, rb, tb, bb, dx, dy; PLFLT xsize, ysize, size, xscale, yscale, scale; PLFLT spxmin, spxmax, spymin, spymax; PLFLT vpxmin, vpxmax, vpymin, vpymax; if (plsc->level < 1) { plabort("plenv: Please call plinit first"); return; } if (xmin == xmax) { plabort("plenv: Invalid xmin and xmax arguments"); return; } if (ymin == ymax) { plabort("plenv: Invalid ymin and ymax arguments"); return; } if (just < -1 || just > 2) { plabort("plenv: Invalid just option"); return; } if (plsc->nsubx * plsc->nsuby == 1) /* not multiplot mode */ old = 1; if (old == 1) pladv(0); else plclear(); if (just == 0) plvsta(); else if (just == 1){ lb = 8.0 * plsc->chrht; rb = 5.0 * plsc->chrht; tb = 5.0 * plsc->chrht; bb = 5.0 * plsc->chrht; dx = ABS(xmax - xmin); dy = ABS(ymax - ymin); plgspa(&spxmin, &spxmax, &spymin, &spymax); xsize = spxmax - spxmin; ysize = spymax - spymin; xscale = dx / (xsize - lb - rb); yscale = dy / (ysize - tb - bb); scale = MAX(xscale, yscale); vpxmin = MAX(lb, 0.5 * (xsize - dx / scale)); vpxmax = vpxmin + (dx / scale); vpymin = MAX(bb, 0.5 * (ysize - dy / scale)); vpymax = vpymin + (dy / scale); plsvpa(vpxmin, vpxmax, vpymin, vpymax); } else if(just == 2) { lb = 8.0 * plsc->chrht; rb = 5.0 * plsc->chrht; tb = 5.0 * plsc->chrht; bb = 5.0 * plsc->chrht; plgspa(&spxmin, &spxmax, &spymin, &spymax); xsize = spxmax - spxmin; ysize = spymax - spymin; size = MIN(xsize-lb-rb, ysize-tb-bb); dx = (xsize-size-lb-rb)/2; vpxmin = lb + dx; vpxmax = vpxmin + size; dy = (ysize-size-bb-tb)/2; vpymin = bb + dy; vpymax = vpymin + size; plsvpa(vpxmin, vpxmax, vpymin, vpymax); } plwind(xmin, xmax, ymin, ymax); switch (axis) { case -2: break; case -1: plbox("bc", (PLFLT) 0.0, 0, "bc", (PLFLT) 0.0, 0); break; case 0: plbox("bcnst", (PLFLT) 0.0, 0, "bcnstv", (PLFLT) 0.0, 0); break; case 1: plbox("abcnst", (PLFLT) 0.0, 0, "abcnstv", (PLFLT) 0.0, 0); break; case 2: plbox("abcgnst", (PLFLT) 0.0, 0, "abcgnstv", (PLFLT) 0.0, 0); break; case 3: plbox("abcgnsth", (PLFLT) 0.0, 0, "abcgnstvh", (PLFLT) 0.0, 0); break; case 10: plbox("bclnst", (PLFLT) 0.0, 0, "bcnstv", (PLFLT) 0.0, 0); break; case 11: plbox("abclnst", (PLFLT) 0.0, 0, "abcnstv", (PLFLT) 0.0, 0); break; case 12: plbox("abcglnst", (PLFLT) 0.0, 0, "abcgnstv", (PLFLT) 0.0, 0); break; case 13: plbox("abcglnsth", (PLFLT) 0.0, 0, "abcgnstvh", (PLFLT) 0.0, 0); break; case 20: plbox("bcnst", (PLFLT) 0.0, 0, "bclnstv", (PLFLT) 0.0, 0); break; case 21: plbox("abcnst", (PLFLT) 0.0, 0, "abclnstv", (PLFLT) 0.0, 0); break; case 22: plbox("abcgnst", (PLFLT) 0.0, 0, "abcglnstv", (PLFLT) 0.0, 0); break; case 23: plbox("abcgnsth", (PLFLT) 0.0, 0, "abcglnstvh", (PLFLT) 0.0, 0); break; case 30: plbox("bclnst", (PLFLT) 0.0, 0, "bclnstv", (PLFLT) 0.0, 0); break; case 31: plbox("abclnst", (PLFLT) 0.0, 0, "abclnstv", (PLFLT) 0.0, 0); break; case 32: plbox("abcglnst", (PLFLT) 0.0, 0, "abcglnstv", (PLFLT) 0.0, 0); break; case 33: plbox("abcglnsth", (PLFLT) 0.0, 0, "abcglnstvh", (PLFLT) 0.0, 0); break; default: plwarn("plenv: Invalid axis argument"); } }
bool plotNoiseStandardDeviation(const hoNDArray< std::complex<T> >& m, const std::vector<std::string>& coilStrings, const std::string& xlabel, const std::string& ylabel, const std::string& title, size_t xsize, size_t ysize, bool trueColor, hoNDArray<float>& plotIm) { try { size_t CHA = m.get_size(0); GADGET_CHECK_RETURN_FALSE(coilStrings.size() == CHA); hoNDArray<double> xd, yd, yd2; xd.create(CHA); yd.create(CHA); size_t c; for (c = 0; c < CHA; c++) { xd(c) = c+1; yd(c) = std::sqrt( std::abs(m(c, c)) ); } double maxY = Gadgetron::max(&yd); yd2 = yd; std::sort(yd2.begin(), yd2.end()); double medY = yd2(CHA / 2); // increase dot line to be 1 sigma ~= 33% double medRange = 0.33; if (maxY < medY*(1 + medRange)) { maxY = medY*(1 + medRange); } hoNDArray<unsigned char> im; im.create(3, xsize, ysize); Gadgetron::clear(im); plsdev("mem"); plsmem(im.get_size(1), im.get_size(2), im.begin()); plinit(); plfont(2); pladv(0); plvpor(0.15, 0.75, 0.1, 0.8); plwind(0, CHA+1, 0, maxY*1.05); plcol0(15); plbox("bcnst", 0.0, 0, "bcnstv", 0.0, 0); std::string gly; getPlotGlyph(0, gly); // circle plstring(CHA, xd.begin(), yd.begin(), gly.c_str()); // draw the median line pllsty(1); double px[2], py[2]; px[0] = 0; px[1] = CHA+1; py[0] = medY; py[1] = medY; plline(2, px, py); pllsty(2); py[0] = medY*(1 - medRange); py[1] = medY*(1 - medRange); plline(2, px, py); py[0] = medY*(1 + medRange); py[1] = medY*(1 + medRange); plline(2, px, py); plmtex("b", 3.2, 0.5, 0.5, xlabel.c_str()); plmtex("t", 2.0, 0.5, 0.5, title.c_str()); plmtex("l", 5.0, 0.5, 0.5, ylabel.c_str()); // draw the legend std::vector<PLINT> opt_array(CHA), text_colors(CHA), line_colors(CHA), line_styles(CHA), symbol_numbers(CHA), symbol_colors(CHA); std::vector<PLFLT> symbol_scales(CHA), line_widths(CHA), box_scales(CHA, 1); std::vector<const char*> symbols(CHA); PLFLT legend_width, legend_height; std::vector<const char*> legend_text(CHA); std::vector<std::string> legends(CHA); size_t n; for (n = 0; n < CHA; n++) { opt_array[n] = PL_LEGEND_SYMBOL; text_colors[n] = 15; line_colors[n] = 15; line_styles[n] = (n % 8 + 1); line_widths[n] = 0.2; symbol_colors[n] = 15; symbol_scales[n] = 0.75; symbol_numbers[n] = 1; symbols[n] = gly.c_str(); std::ostringstream ostr; ostr << n+1 << ":" << coilStrings[n]; legends[n] = ostr.str(); legend_text[n] = legends[n].c_str(); } pllegend(&legend_width, &legend_height, PL_LEGEND_BACKGROUND, PL_POSITION_OUTSIDE | PL_POSITION_RIGHT, 0.02, // x 0.0, // y 0.05, // plot_width 0, // bg_color 15, // bb_color 1, // bb_style 0, // nrow 0, // ncolumn CHA, // nlegend &opt_array[0], 0.05, // text_offset 0.5, // text_scale 1.0, // text_spacing 0.5, // text_justification &text_colors[0], (const char **)(&legend_text[0]), NULL, // box_colors NULL, // box_patterns &box_scales[0], // box_scales NULL, // box_line_widths &line_colors[0], &line_styles[0], &line_widths[0], &symbol_colors[0], &symbol_scales[0], &symbol_numbers[0], (const char **)(&symbols[0]) ); plend(); outputPlotIm(im, trueColor, plotIm); } catch (...) { GERROR_STREAM("Errors happened in plotNoiseStandardDeviation(...) ... "); return false; } return true; }
template <typename T> EXPORTGTPLPLOT bool plotCurves(const std::vector<hoNDArray<T> >& x, const std::vector<hoNDArray<T> >& y, const std::string& xlabel, const std::string& ylabel, const std::string& title, const std::vector<std::string>& legend, const std::vector<std::string>& symbols, size_t xsize, size_t ysize, T xlim[2], T ylim[2], bool trueColor, bool drawLine, hoNDArray<float>& plotIm) { try { GADGET_CHECK_RETURN_FALSE(x.size()>0); GADGET_CHECK_RETURN_FALSE(y.size()>0); GADGET_CHECK_RETURN_FALSE(x.size() == y.size()); T minX = xlim[0]; T maxX = xlim[1]; T minY = ylim[0]; T maxY = ylim[1]; plsdev("mem"); hoNDArray<unsigned char> im; im.create(3, xsize, ysize); Gadgetron::clear(im); plsmem(im.get_size(1), im.get_size(2), im.begin()); plinit(); plfont(2); pladv(0); if (legend.size() == x.size()) { plvpor(0.11, 0.75, 0.1, 0.9); } else { plvpor(0.15, 0.85, 0.1, 0.9); } T spaceX = 0.01*(maxX - minX); T spaceY = 0.05*(maxY - minY); plwind(minX - spaceX, maxX + spaceX, minY - spaceY, maxY + spaceY); plcol0(15); plbox("bgcnst", 0.0, 0, "bgcnstv", 0.0, 0); // int mark[2], space[2]; //mark[0] = 4000; //space[0] = 2500; //plstyl(1, mark, space); size_t num = x.size(); size_t n; hoNDArray<double> xd, yd; // draw lines for (n = 0; n < num; n++) { size_t N = y[n].get_size(0); xd.copyFrom(x[n]); yd.copyFrom(y[n]); if (drawLine) { int c; getPlotColor(n, c); plcol0(c); pllsty(n % 8 + 1); plline(N, xd.begin(), yd.begin()); } std::string gly; if(symbols.size()>n) { gly = symbols[n]; } else getPlotGlyph(n, gly); plstring(N, xd.begin(), yd.begin(), gly.c_str()); } plcol0(15); plmtex("b", 3.2, 0.5, 0.5, xlabel.c_str()); plmtex("t", 2.0, 0.5, 0.5, title.c_str()); plmtex("l", 5.0, 0.5, 0.5, ylabel.c_str()); // draw the legend if (legend.size() == x.size()) { std::vector<PLINT> opt_array(num), text_colors(num), line_colors(num), line_styles(num), symbol_numbers(num), symbol_colors(num); std::vector<PLFLT> symbol_scales(num), line_widths(num), box_scales(num, 1); std::vector<std::string> glyphs(num); std::vector<const char*> symbols(num); PLFLT legend_width, legend_height; std::vector<const char*> legend_text(num); for (n = 0; n < num; n++) { int c; getPlotColor(n, c); getPlotGlyph(n, glyphs[n]); opt_array[n] = PL_LEGEND_SYMBOL | PL_LEGEND_LINE; text_colors[n] = 15; line_colors[n] = c; line_styles[n] = (n%8+1); line_widths[n] = 0.2; symbol_colors[n] = c; symbol_scales[n] = 0.75; symbol_numbers[n] = 1; symbols[n] = glyphs[n].c_str(); legend_text[n] = legend[n].c_str(); } pllegend(&legend_width, &legend_height, PL_LEGEND_BACKGROUND, PL_POSITION_OUTSIDE | PL_POSITION_RIGHT | PL_POSITION_TOP, 0.02, // x 0.0, // y 0.05, // plot_width 0, // bg_color 15, // bb_color 1, // bb_style 0, // nrow 0, // ncolumn num, // nlegend &opt_array[0], 0.05, // text_offset 0.35, // text_scale 1.0, // text_spacing 0.5, // text_justification &text_colors[0], (const char **)(&legend_text[0]), NULL, // box_colors NULL, // box_patterns &box_scales[0], // box_scales NULL, // box_line_widths &line_colors[0], &line_styles[0], &line_widths[0], &symbol_colors[0], &symbol_scales[0], &symbol_numbers[0], (const char **)(&symbols[0]) ); } plend(); outputPlotIm(im, trueColor, plotIm); } catch (...) { GERROR_STREAM("Errors happened in plotCurves(xlim, ylim) ... "); return false; } return true; }
int main( int argc, const char *argv[] ) { int i, j, dthet, theta0, theta1, theta; PLFLT just, dx, dy; static PLFLT x[500], y[500], per[5]; per[0] = 10.; per[1] = 32.; per[2] = 12.; per[3] = 30.; per[4] = 16.; // Parse and process command line arguments (void) plparseopts( &argc, argv, PL_PARSE_FULL ); // Initialize plplot plinit(); pladv( 0 ); // Ensure window has aspect ratio of one so circle is // plotted as a circle. plvasp( 1.0 ); plwind( 0., 10., 0., 10. ); // plenv(0., 10., 0., 10., 1, -2); plcol0( 2 ); // n.b. all theta quantities scaled by 2*M_PI/500 to be integers to avoid // floating point logic problems. theta0 = 0; dthet = 1; for ( i = 0; i <= 4; i++ ) { j = 0; x[j] = 5.; y[j++] = 5.; // n.b. the theta quantities multiplied by 2*M_PI/500 afterward so // in fact per is interpreted as a percentage. theta1 = (int) ( theta0 + 5 * per[i] ); if ( i == 4 ) theta1 = 500; for ( theta = theta0; theta <= theta1; theta += dthet ) { x[j] = 5 + 3 * cos( ( 2. * M_PI / 500. ) * theta ); y[j++] = 5 + 3 * sin( ( 2. * M_PI / 500. ) * theta ); } plcol0( i + 1 ); plpsty( ( i + 3 ) % 8 + 1 ); plfill( j, x, y ); plcol0( 1 ); plline( j, x, y ); just = ( 2. * M_PI / 500. ) * ( theta0 + theta1 ) / 2.; dx = .25 * cos( just ); dy = .25 * sin( just ); if ( ( theta0 + theta1 ) < 250 || ( theta0 + theta1 ) > 750 ) just = 0.; else just = 1.; plptex( ( x[j / 2] + dx ), ( y[j / 2] + dy ), 1.0, 0.0, just, text[i] ); theta0 = theta - dthet; } plfont( 2 ); plschr( 0., 1.3 ); plptex( 5.0, 9.0, 1.0, 0.0, 0.5, "Percentage of Sales" ); // Don't forget to call PLEND to finish off! plend(); exit( 0 ); }
int main(int argc, char *argv[]) { int i, j, k; PLFLT *x, *y, **z; PLFLT xx, yy; int nlevel = LEVELS; PLFLT clevel[LEVELS]; PLFLT zmin, zmax, step; /* Parse and process command line arguments */ (void) plparseopts(&argc, argv, PL_PARSE_FULL); /* Initialize plplot */ plinit(); x = (PLFLT *) calloc(XPTS, sizeof(PLFLT)); y = (PLFLT *) calloc(YPTS, sizeof(PLFLT)); plAlloc2dGrid(&z, XPTS, YPTS); for (i = 0; i < XPTS; i++) { x[i] = 3. * (double) (i - (XPTS / 2)) / (double) (XPTS / 2); } for (i = 0; i < YPTS; i++) y[i] = 3.* (double) (i - (YPTS / 2)) / (double) (YPTS / 2); for (i = 0; i < XPTS; i++) { xx = x[i]; for (j = 0; j < YPTS; j++) { yy = y[j]; z[i][j] = 3. * (1.-xx)*(1.-xx) * exp(-(xx*xx) - (yy+1.)*(yy+1.)) - 10. * (xx/5. - pow(xx,3.) - pow(yy,5.)) * exp(-xx*xx-yy*yy) - 1./3. * exp(-(xx+1)*(xx+1) - (yy*yy)); if(0) { /* Jungfraujoch/Interlaken */ if (z[i][j] < -1.) z[i][j] = -1.; } } } plMinMax2dGrid(z, XPTS, YPTS, &zmax, &zmin); step = (zmax - zmin)/(nlevel+1); for (i=0; i<nlevel; i++) clevel[i] = zmin + step + step*i; cmap1_init(); for (k = 0; k < 2; k++) { for (i=0; i<4; i++) { pladv(0); plcol0(1); plvpor(0.0, 1.0, 0.0, 0.9); plwind(-1.0, 1.0, -1.0, 1.5); plw3d(1.0, 1.0, 1.2, -3.0, 3.0, -3.0, 3.0, zmin, zmax, alt[k], az[k]); plbox3("bnstu", "x axis", 0.0, 0, "bnstu", "y axis", 0.0, 0, "bcdmnstuv", "z axis", 0.0, 4); plcol0(2); /* wireframe plot */ if (i==0) plmesh(x, y, z, XPTS, YPTS, opt[k]); /* magnitude colored wireframe plot */ else if (i==1) plmesh(x, y, z, XPTS, YPTS, opt[k] | MAG_COLOR); /* magnitude colored wireframe plot with sides */ else if (i==2) plot3d(x, y, z, XPTS, YPTS, opt[k] | MAG_COLOR, 1); /* magnitude colored wireframe plot with base contour */ else if (i==3) plmeshc(x, y, z, XPTS, YPTS, opt[k] | MAG_COLOR | BASE_CONT, clevel, nlevel); plcol0(3); plmtex("t", 1.0, 0.5, 0.5, title[k]); } } /* Clean up */ free((void *) x); free((void *) y); plFree2dGrid(z, XPTS, YPTS); plend(); exit(0); }
int main( int argc, const char *argv[] ) { int i, j, k; int npts = 0; PLFLT xextreme[10][2]; PLFLT yextreme[10][2]; PLFLT x0[10]; PLFLT y0[10]; // Parse and process command line arguments (void) plparseopts( &argc, argv, PL_PARSE_FULL ); // Initialize plplot plssub( 3, 3 ); plinit(); xextreme[0][0] = -120.0; xextreme[0][1] = 120.0; yextreme[0][0] = -120.0; yextreme[0][1] = 120.0; xextreme[1][0] = -120.0; xextreme[1][1] = 120.0; yextreme[1][0] = 20.0; yextreme[1][1] = 120.0; xextreme[2][0] = -120.0; xextreme[2][1] = 120.0; yextreme[2][0] = -20.0; yextreme[2][1] = 120.0; xextreme[3][0] = -80.0; xextreme[3][1] = 80.0; yextreme[3][0] = -20.0; yextreme[3][1] = 120.0; xextreme[4][0] = -220.0; xextreme[4][1] = -120.0; yextreme[4][0] = -120.0; yextreme[4][1] = 120.0; xextreme[5][0] = -20.0; xextreme[5][1] = 20.0; yextreme[5][0] = -120.0; yextreme[5][1] = 120.0; xextreme[6][0] = -20.0; xextreme[6][1] = 20.0; yextreme[6][0] = -20.0; yextreme[6][1] = 20.0; xextreme[7][0] = -80.0; xextreme[7][1] = 80.0; yextreme[7][0] = -80.0; yextreme[7][1] = 80.0; xextreme[8][0] = 20.0; xextreme[8][1] = 120.0; yextreme[8][0] = -120.0; yextreme[8][1] = 120.0; for ( k = 0; k < 2; k++ ) { for ( j = 0; j < 4; j++ ) { if ( j == 0 ) { // Polygon 1: a diamond x0[0] = 0; y0[0] = -100; x0[1] = -100; y0[1] = 0; x0[2] = 0; y0[2] = 100; x0[3] = 100; y0[3] = 0; npts = 4; } if ( j == 1 ) { // Polygon 1: a diamond - reverse direction x0[3] = 0; y0[3] = -100; x0[2] = -100; y0[2] = 0; x0[1] = 0; y0[1] = 100; x0[0] = 100; y0[0] = 0; npts = 4; } if ( j == 2 ) { // Polygon 2: a square with punctures x0[0] = -100; y0[0] = -100; x0[1] = -100; y0[1] = -80; x0[2] = 80; y0[2] = 0; x0[3] = -100; y0[3] = 80; x0[4] = -100; y0[4] = 100; x0[5] = -80; y0[5] = 100; x0[6] = 0; y0[6] = 80; x0[7] = 80; y0[7] = 100; x0[8] = 100; y0[8] = 100; x0[9] = 100; y0[9] = -100; npts = 10; } if ( j == 3 ) { // Polygon 2: a square with punctures - reversed direction x0[9] = -100; y0[9] = -100; x0[8] = -100; y0[8] = -80; x0[7] = 80; y0[7] = 0; x0[6] = -100; y0[6] = 80; x0[5] = -100; y0[5] = 100; x0[4] = -80; y0[4] = 100; x0[3] = 0; y0[3] = 80; x0[2] = 80; y0[2] = 100; x0[1] = 100; y0[1] = 100; x0[0] = 100; y0[0] = -100; npts = 10; } for ( i = 0; i < 9; i++ ) { pladv( 0 ); plvsta(); plwind( xextreme[i][0], xextreme[i][1], yextreme[i][0], yextreme[i][1] ); plcol0( 2 ); plbox( "bc", 1.0, 0, "bcnv", 10.0, 0 ); plcol0( 1 ); plpsty( 0 ); if ( k == 0 ) plfill( npts, x0, y0 ); else plgradient( npts, x0, y0, 45. ); plcol0( 2 ); pllsty( 1 ); plline( npts, x0, y0 ); } } } // Don't forget to call plend() to finish off! plend(); exit( 0 ); }
int main( int argc, const char *argv[] ) { PLFLT *x, *y, **z, xmin = 0., xmax = 1.0, xmid = 0.5 * ( xmax + xmin ), xrange = xmax - xmin, ymin = 0., ymax = 1.0, ymid = 0.5 * ( ymax + ymin ), yrange = ymax - ymin, zmin = 0., zmax = 1.0, zmid = 0.5 * ( zmax + zmin ), zrange = zmax - zmin, ysmin = ymin + 0.1 * yrange, ysmax = ymax - 0.1 * yrange, ysrange = ysmax - ysmin, dysrot = ysrange / (PLFLT) ( NROTATION - 1 ), dysshear = ysrange / (PLFLT) ( NSHEAR - 1 ), zsmin = zmin + 0.1 * zrange, zsmax = zmax - 0.1 * zrange, zsrange = zsmax - zsmin, dzsrot = zsrange / (PLFLT) ( NROTATION - 1 ), dzsshear = zsrange / (PLFLT) ( NSHEAR - 1 ), ys, zs, x_inclination, y_inclination, z_inclination, x_shear, y_shear, z_shear, omega, sin_omega, cos_omega, domega; int i, j; PLFLT radius, pitch, xpos, ypos, zpos; // p1string must be exactly one character + the null termination // character. char p1string[] = "O"; const char *pstring = "The future of our civilization depends on software freedom."; // Allocate and define the minimal x, y, and z to insure 3D box x = (PLFLT *) calloc( XPTS, sizeof ( PLFLT ) ); y = (PLFLT *) calloc( YPTS, sizeof ( PLFLT ) ); plAlloc2dGrid( &z, XPTS, YPTS ); for ( i = 0; i < XPTS; i++ ) { x[i] = xmin + (double) i * ( xmax - xmin ) / (double) ( XPTS - 1 ); } for ( j = 0; j < YPTS; j++ ) y[j] = ymin + (double) j * ( ymax - ymin ) / (double) ( YPTS - 1 ); for ( i = 0; i < XPTS; i++ ) { for ( j = 0; j < YPTS; j++ ) { z[i][j] = 0.; } } // Parse and process command line arguments (void) plparseopts( &argc, argv, PL_PARSE_FULL ); plinit(); // Page 1: Demonstrate inclination and shear capability pattern. pladv( 0 ); plvpor( -0.15, 1.15, -0.05, 1.05 ); plwind( -1.2, 1.2, -0.8, 1.5 ); plw3d( 1.0, 1.0, 1.0, xmin, xmax, ymin, ymax, zmin, zmax, 20., 45. ); plcol0( 2 ); plbox3( "b", "", xmax - xmin, 0, "b", "", ymax - ymin, 0, "bcd", "", zmax - zmin, 0 ); // z = zmin. plschr( 0., 1.0 ); for ( i = 0; i < NREVOLUTION; i++ ) { omega = 2. * M_PI * ( (PLFLT) i / (PLFLT) NREVOLUTION ); sin_omega = sin( omega ); cos_omega = cos( omega ); x_inclination = 0.5 * xrange * cos_omega; y_inclination = 0.5 * yrange * sin_omega; z_inclination = 0.; x_shear = -0.5 * xrange * sin_omega; y_shear = 0.5 * yrange * cos_omega; z_shear = 0.; plptex3( xmid, ymid, zmin, x_inclination, y_inclination, z_inclination, x_shear, y_shear, z_shear, 0.0, " revolution" ); } // x = xmax. plschr( 0., 1.0 ); for ( i = 0; i < NREVOLUTION; i++ ) { omega = 2. * M_PI * ( (PLFLT) i / (PLFLT) NREVOLUTION ); sin_omega = sin( omega ); cos_omega = cos( omega ); x_inclination = 0.; y_inclination = -0.5 * yrange * cos_omega; z_inclination = 0.5 * zrange * sin_omega; x_shear = 0.; y_shear = 0.5 * yrange * sin_omega; z_shear = 0.5 * zrange * cos_omega; plptex3( xmax, ymid, zmid, x_inclination, y_inclination, z_inclination, x_shear, y_shear, z_shear, 0.0, " revolution" ); } // y = ymax. plschr( 0., 1.0 ); for ( i = 0; i < NREVOLUTION; i++ ) { omega = 2. * M_PI * ( (PLFLT) i / (PLFLT) NREVOLUTION ); sin_omega = sin( omega ); cos_omega = cos( omega ); x_inclination = 0.5 * xrange * cos_omega; y_inclination = 0.; z_inclination = 0.5 * zrange * sin_omega; x_shear = -0.5 * xrange * sin_omega; y_shear = 0.; z_shear = 0.5 * zrange * cos_omega; plptex3( xmid, ymax, zmid, x_inclination, y_inclination, z_inclination, x_shear, y_shear, z_shear, 0.0, " revolution" ); } // Draw minimal 3D grid to finish defining the 3D box. plmesh( x, y, (const PLFLT * const *) z, XPTS, YPTS, DRAW_LINEXY ); // Page 2: Demonstrate rotation of string around its axis. pladv( 0 ); plvpor( -0.15, 1.15, -0.05, 1.05 ); plwind( -1.2, 1.2, -0.8, 1.5 ); plw3d( 1.0, 1.0, 1.0, xmin, xmax, ymin, ymax, zmin, zmax, 20., 45. ); plcol0( 2 ); plbox3( "b", "", xmax - xmin, 0, "b", "", ymax - ymin, 0, "bcd", "", zmax - zmin, 0 ); // y = ymax. plschr( 0., 1.0 ); x_inclination = 1.; y_inclination = 0.; z_inclination = 0.; x_shear = 0.; for ( i = 0; i < NROTATION; i++ ) { omega = 2. * M_PI * ( (PLFLT) i / (PLFLT) NROTATION ); sin_omega = sin( omega ); cos_omega = cos( omega ); y_shear = 0.5 * yrange * sin_omega; z_shear = 0.5 * zrange * cos_omega; zs = zsmax - dzsrot * (PLFLT) i; plptex3( xmid, ymax, zs, x_inclination, y_inclination, z_inclination, x_shear, y_shear, z_shear, 0.5, "rotation for y = y#dmax#u" ); } // x = xmax. plschr( 0., 1.0 ); x_inclination = 0.; y_inclination = -1.; z_inclination = 0.; y_shear = 0.; for ( i = 0; i < NROTATION; i++ ) { omega = 2. * M_PI * ( (PLFLT) i / (PLFLT) NROTATION ); sin_omega = sin( omega ); cos_omega = cos( omega ); x_shear = 0.5 * xrange * sin_omega; z_shear = 0.5 * zrange * cos_omega; zs = zsmax - dzsrot * (PLFLT) i; plptex3( xmax, ymid, zs, x_inclination, y_inclination, z_inclination, x_shear, y_shear, z_shear, 0.5, "rotation for x = x#dmax#u" ); } // z = zmin. plschr( 0., 1.0 ); x_inclination = 1.; y_inclination = 0.; z_inclination = 0.; x_shear = 0.; for ( i = 0; i < NROTATION; i++ ) { omega = 2. * M_PI * ( (PLFLT) i / (PLFLT) NROTATION ); sin_omega = sin( omega ); cos_omega = cos( omega ); y_shear = 0.5 * yrange * cos_omega; z_shear = 0.5 * zrange * sin_omega; ys = ysmax - dysrot * (PLFLT) i; plptex3( xmid, ys, zmin, x_inclination, y_inclination, z_inclination, x_shear, y_shear, z_shear, 0.5, "rotation for z = z#dmin#u" ); } // Draw minimal 3D grid to finish defining the 3D box. plmesh( x, y, (const PLFLT * const *) z, XPTS, YPTS, DRAW_LINEXY ); // Page 3: Demonstrate shear of string along its axis. // Work around xcairo and pngcairo (but not pscairo) problems for // shear vector too close to axis of string. (N.B. no workaround // would be domega = 0.) domega = 0.05; pladv( 0 ); plvpor( -0.15, 1.15, -0.05, 1.05 ); plwind( -1.2, 1.2, -0.8, 1.5 ); plw3d( 1.0, 1.0, 1.0, xmin, xmax, ymin, ymax, zmin, zmax, 20., 45. ); plcol0( 2 ); plbox3( "b", "", xmax - xmin, 0, "b", "", ymax - ymin, 0, "bcd", "", zmax - zmin, 0 ); // y = ymax. plschr( 0., 1.0 ); x_inclination = 1.; y_inclination = 0.; z_inclination = 0.; y_shear = 0.; for ( i = 0; i < NSHEAR; i++ ) { omega = domega + 2. * M_PI * ( (PLFLT) i / (PLFLT) NSHEAR ); sin_omega = sin( omega ); cos_omega = cos( omega ); x_shear = 0.5 * xrange * sin_omega; z_shear = 0.5 * zrange * cos_omega; zs = zsmax - dzsshear * (PLFLT) i; plptex3( xmid, ymax, zs, x_inclination, y_inclination, z_inclination, x_shear, y_shear, z_shear, 0.5, "shear for y = y#dmax#u" ); } // x = xmax. plschr( 0., 1.0 ); x_inclination = 0.; y_inclination = -1.; z_inclination = 0.; x_shear = 0.; for ( i = 0; i < NSHEAR; i++ ) { omega = domega + 2. * M_PI * ( (PLFLT) i / (PLFLT) NSHEAR ); sin_omega = sin( omega ); cos_omega = cos( omega ); y_shear = -0.5 * yrange * sin_omega; z_shear = 0.5 * zrange * cos_omega; zs = zsmax - dzsshear * (PLFLT) i; plptex3( xmax, ymid, zs, x_inclination, y_inclination, z_inclination, x_shear, y_shear, z_shear, 0.5, "shear for x = x#dmax#u" ); } // z = zmin. plschr( 0., 1.0 ); x_inclination = 1.; y_inclination = 0.; z_inclination = 0.; z_shear = 0.; for ( i = 0; i < NSHEAR; i++ ) { omega = domega + 2. * M_PI * ( (PLFLT) i / (PLFLT) NSHEAR ); sin_omega = sin( omega ); cos_omega = cos( omega ); y_shear = 0.5 * yrange * cos_omega; x_shear = 0.5 * xrange * sin_omega; ys = ysmax - dysshear * (PLFLT) i; plptex3( xmid, ys, zmin, x_inclination, y_inclination, z_inclination, x_shear, y_shear, z_shear, 0.5, "shear for z = z#dmin#u" ); } // Draw minimal 3D grid to finish defining the 3D box. plmesh( x, y, (const PLFLT * const *) z, XPTS, YPTS, DRAW_LINEXY ); // Page 4: Demonstrate drawing a string on a 3D path. pladv( 0 ); plvpor( -0.15, 1.15, -0.05, 1.05 ); plwind( -1.2, 1.2, -0.8, 1.5 ); plw3d( 1.0, 1.0, 1.0, xmin, xmax, ymin, ymax, zmin, zmax, 40., -30. ); plcol0( 2 ); plbox3( "b", "", xmax - xmin, 0, "b", "", ymax - ymin, 0, "bcd", "", zmax - zmin, 0 ); plschr( 0., 1.2 ); // domega controls the spacing between the various characters of the // string and also the maximum value of omega for the given number // of characters in *pstring. domega = 2. * M_PI / (double) strlen( pstring ); omega = 0.; // 3D function is a helix of the given radius and pitch radius = 0.5; pitch = 1. / ( 2. * M_PI ); while ( *pstring ) { sin_omega = sin( omega ); cos_omega = cos( omega ); xpos = xmid + radius * sin_omega; ypos = ymid - radius * cos_omega; zpos = zmin + pitch * omega; // In general, the inclination is proportional to the derivative of // the position wrt theta. x_inclination = radius * cos_omega;; y_inclination = radius * sin_omega; z_inclination = pitch; // The shear vector should be perpendicular to the 3D line with Z // component maximized, but for low pitch a good approximation is // a constant vector that is parallel to the Z axis. x_shear = 0.; y_shear = 0.; z_shear = 1.; *p1string = *pstring; plptex3( xpos, ypos, zpos, x_inclination, y_inclination, z_inclination, x_shear, y_shear, z_shear, 0.5, p1string ); pstring++; omega += domega; } // Draw minimal 3D grid to finish defining the 3D box. plmesh( x, y, (const PLFLT * const *) z, XPTS, YPTS, DRAW_LINEXY ); // Page 5: Demonstrate plmtex3 axis labelling capability pladv( 0 ); plvpor( -0.15, 1.15, -0.05, 1.05 ); plwind( -1.2, 1.2, -0.8, 1.5 ); plw3d( 1.0, 1.0, 1.0, xmin, xmax, ymin, ymax, zmin, zmax, 20., 45. ); plcol0( 2 ); plbox3( "b", "", xmax - xmin, 0, "b", "", ymax - ymin, 0, "bcd", "", zmax - zmin, 0 ); plschr( 0., 1.0 ); plmtex3( "xp", 3.0, 0.5, 0.5, "Arbitrarily displaced" ); plmtex3( "xp", 4.5, 0.5, 0.5, "primary X-axis label" ); plmtex3( "xs", -2.5, 0.5, 0.5, "Arbitrarily displaced" ); plmtex3( "xs", -1.0, 0.5, 0.5, "secondary X-axis label" ); plmtex3( "yp", 3.0, 0.5, 0.5, "Arbitrarily displaced" ); plmtex3( "yp", 4.5, 0.5, 0.5, "primary Y-axis label" ); plmtex3( "ys", -2.5, 0.5, 0.5, "Arbitrarily displaced" ); plmtex3( "ys", -1.0, 0.5, 0.5, "secondary Y-axis label" ); plmtex3( "zp", 4.5, 0.5, 0.5, "Arbitrarily displaced" ); plmtex3( "zp", 3.0, 0.5, 0.5, "primary Z-axis label" ); plmtex3( "zs", -2.5, 0.5, 0.5, "Arbitrarily displaced" ); plmtex3( "zs", -1.0, 0.5, 0.5, "secondary Z-axis label" ); // Draw minimal 3D grid to finish defining the 3D box. plmesh( x, y, (const PLFLT * const *) z, XPTS, YPTS, DRAW_LINEXY ); // Clean up. free( (void *) x ); free( (void *) y ); plFree2dGrid( z, XPTS, YPTS ); plend(); exit( 0 ); }
void shade(void) { int i, j; PLFLT x, y, argx, argy, distort; PLFLT **z, **w, zmin, zmax; PLFLT xg1[XPTS], yg1[YPTS]; PLcGrid cgrid1; PLcGrid2 cgrid2; PLFLT shade_min, shade_max, sh_color; PLINT sh_cmap = 1, sh_width; PLINT min_color = 1, min_width = 0, max_color = 0, max_width = 0; /* Set up function arrays */ plAlloc2dGrid(&z, XPTS, YPTS); plAlloc2dGrid(&w, XPTS, YPTS); /* Set up data array */ for (i = 0; i < XPTS; i++) { x = (double) (i - (XPTS / 2)) / (double) (XPTS / 2); for (j = 0; j < YPTS; j++) { y = (double) (j - (YPTS / 2)) / (double) (YPTS / 2) - 1.0; z[i][j] = - sin(7.*x) * cos(7.*y) + x*x - y*y; w[i][j] = - cos(7.*x) * sin(7.*y) + 2 * x * y; } } f2mnmx(z, XPTS, YPTS, &zmin, &zmax); for (i = 0; i < NCONTR; i++) clevel[i] = zmin + (zmax - zmin) * (i + 0.5) / (PLFLT) NCONTR; /* Set up coordinate grids */ cgrid1.xg = xg1; cgrid1.yg = yg1; cgrid1.nx = XPTS; cgrid1.ny = YPTS; plAlloc2dGrid(&cgrid2.xg, XPTS, YPTS); plAlloc2dGrid(&cgrid2.yg, XPTS, YPTS); cgrid2.nx = XPTS; cgrid2.ny = YPTS; for (i = 0; i < XPTS; i++) { for (j = 0; j < YPTS; j++) { mypltr((PLFLT) i, (PLFLT) j, &x, &y, NULL); argx = x * PI/2; argy = y * PI/2; distort = 0.4; cgrid1.xg[i] = x + distort * cos(argx); cgrid1.yg[j] = y - distort * cos(argy); cgrid2.xg[i][j] = x + distort * cos(argx) * cos(argy); cgrid2.yg[i][j] = y - distort * cos(argx) * cos(argy); } } /* Plot using identity transform */ pladv(0); plvpor(0.1, 0.9, 0.1, 0.9); plwind(-1.0, 1.0, -1.0, 1.0); for (i = 0; i < NCONTR; i++) { shade_min = zmin + (zmax - zmin) * i / (PLFLT) NCONTR; shade_max = zmin + (zmax - zmin) * (i +1) / (PLFLT) NCONTR; sh_color = i / (PLFLT) (NCONTR-1); sh_width = 2; plpsty(0); plshade(z, XPTS, YPTS, NULL, -1., 1., -1., 1., shade_min, shade_max, sh_cmap, sh_color, sh_width, min_color, min_width, max_color, max_width, plfill, 1, NULL, NULL); } plcol(1); plbox("bcnst", 0.0, 0, "bcnstv", 0.0, 0); plcol(2); /* plcont(w, XPTS, YPTS, 1, XPTS, 1, YPTS, clevel, NCONTR, mypltr, NULL); */ pllab("distance", "altitude", "Bogon density"); /* Clean up */ plFree2dGrid(z, XPTS, YPTS); plFree2dGrid(w, XPTS, YPTS); plFree2dGrid(cgrid2.xg, XPTS, YPTS); plFree2dGrid(cgrid2.yg, XPTS, YPTS); }
void plot1( int type, const char *x_label, const char *y_label, const char *alty_label, const char * legend_text[], const char *title_label, const char *line_label ) { int i; static PLFLT freql[101], ampl[101], phase[101]; PLFLT f0, freq; PLINT nlegend = 2; PLINT opt_array[2]; PLINT text_colors[2]; PLINT line_colors[2]; PLINT line_styles[2]; PLFLT line_widths[2]; PLINT symbol_numbers[2], symbol_colors[2]; PLFLT symbol_scales[2]; const char *symbols[2]; PLFLT legend_width, legend_height; pladv( 0 ); // Set up data for log plot f0 = 1.0; for ( i = 0; i <= 100; i++ ) { freql[i] = -2.0 + i / 20.0; freq = pow( 10.0, freql[i] ); ampl[i] = 20.0 * log10( 1.0 / sqrt( 1.0 + pow( ( freq / f0 ), 2. ) ) ); phase[i] = -( 180.0 / M_PI ) * atan( freq / f0 ); } plvpor( 0.15, 0.85, 0.1, 0.9 ); plwind( -2.0, 3.0, -80.0, 0.0 ); // Try different axis and labelling styles. plcol0( 1 ); switch ( type ) { case 0: plbox( "bclnst", 0.0, 0, "bnstv", 0.0, 0 ); break; case 1: plbox( "bcfghlnst", 0.0, 0, "bcghnstv", 0.0, 0 ); break; } // Plot ampl vs freq plcol0( 2 ); plline( 101, freql, ampl ); plcol0( 2 ); plptex( 1.6, -30.0, 1.0, -20.0, 0.5, line_label ); // Put labels on plcol0( 1 ); plmtex( "b", 3.2, 0.5, 0.5, x_label ); plmtex( "t", 2.0, 0.5, 0.5, title_label ); plcol0( 2 ); plmtex( "l", 5.0, 0.5, 0.5, y_label ); // For the gridless case, put phase vs freq on same plot if ( type == 0 ) { plcol0( 1 ); plwind( -2.0, 3.0, -100.0, 0.0 ); plbox( "", 0.0, 0, "cmstv", 30.0, 3 ); plcol0( 3 ); plline( 101, freql, phase ); plstring( 101, freql, phase, "#(728)" ); plcol0( 3 ); plmtex( "r", 5.0, 0.5, 0.5, alty_label ); } // Draw a legend // First legend entry. opt_array[0] = PL_LEGEND_LINE; text_colors[0] = 2; line_colors[0] = 2; line_styles[0] = 1; line_widths[0] = 1.; // note from the above opt_array the first symbol (and box) indices // do not have to be specified // Second legend entry. opt_array[1] = PL_LEGEND_LINE | PL_LEGEND_SYMBOL; text_colors[1] = 3; line_colors[1] = 3; line_styles[1] = 1; line_widths[1] = 1.; symbol_colors[1] = 3; symbol_scales[1] = 1.; symbol_numbers[1] = 4; symbols[1] = "#(728)"; // from the above opt_arrays we can completely ignore everything // to do with boxes. plscol0a( 15, 32, 32, 32, 0.70 ); pllegend( &legend_width, &legend_height, PL_LEGEND_BACKGROUND | PL_LEGEND_BOUNDING_BOX, 0, 0.0, 0.0, 0.10, 15, 1, 1, 0, 0, nlegend, opt_array, 1.0, 1.0, 2.0, 1., text_colors, (const char **) legend_text, NULL, NULL, NULL, NULL, line_colors, line_styles, line_widths, symbol_colors, symbol_scales, symbol_numbers, (const char **) symbols ); }
int main(int argc, char *argv[]) { PLFLT *x, *y, *z, *clev; PLFLT *xg, *yg, **zg, **szg; PLFLT zmin, zmax, lzm, lzM; long ct; int i, j, k; PLINT alg; char ylab[40], xlab[40]; char *title[] = {"Cubic Spline Approximation", "Delaunay Linear Interpolation", "Natural Neighbors Interpolation", "KNN Inv. Distance Weighted", "3NN Linear Interpolation", "4NN Around Inv. Dist. Weighted"}; PLFLT opt[] = {0., 0., 0., 0., 0., 0.}; xm = ym = -0.2; xM = yM = 0.8; plMergeOpts(options, "x21c options", NULL); plparseopts(&argc, argv, PL_PARSE_FULL); opt[2] = wmin; opt[3] = (PLFLT) knn_order; opt[4] = threshold; /* Initialize plplot */ plinit(); create_data(&x, &y, &z, pts); /* the sampled data */ zmin = z[0]; zmax = z[0]; for (i=1; i<pts; i++) { if (z[i] > zmax) zmax = z[i]; if (z[i] < zmin) zmin = z[i]; } create_grid(&xg, xp, &yg, yp); /* grid the data at */ plAlloc2dGrid(&zg, xp, yp); /* the output grided data */ clev = (PLFLT *) malloc(nl * sizeof(PLFLT)); sprintf(xlab, "Npts=%d gridx=%d gridy=%d", pts, xp, yp); plcol0(1); plenv(xm, xM, ym, yM, 2, 0); plcol0(15); pllab(xlab, "", "The original data"); plcol0(2); plpoin(pts, x, y, 5); pladv(0); plssub(3,2); for (k=0; k<2; k++) { pladv(0); for (alg=1; alg<7; alg++) { ct = clock(); plgriddata(x, y, z, pts, xg, xp, yg, yp, zg, alg, opt[alg-1]); sprintf(xlab, "time=%d ms", (clock() - ct)/1000); sprintf(ylab, "opt=%.3f", opt[alg-1]); /* - CSA can generate NaNs (only interpolates?!). * - DTLI and NNI can generate NaNs for points outside the convex hull * of the data points. * - NNLI can generate NaNs if a sufficiently thick triangle is not found * * PLplot should be NaN/Inf aware, but changing it now is quite a job... * so, instead of not plotting the NaN regions, a weighted average over * the neighbors is done. */ if (alg == GRID_CSA || alg == GRID_DTLI || alg == GRID_NNLI || alg == GRID_NNI) { int ii, jj; PLFLT dist, d; for (i=0; i<xp; i++) { for (j=0; j<yp; j++) { if (isnan(zg[i][j])) { /* average (IDW) over the 8 neighbors */ zg[i][j] = 0.; dist = 0.; for (ii=i-1; ii<=i+1 && ii<xp; ii++) { for (jj=j-1; jj<=j+1 && jj<yp; jj++) { if (ii >= 0 && jj >= 0 && !isnan(zg[ii][jj])) { d = (abs(ii-i) + abs(jj-j)) == 1 ? 1. : 1.4142; zg[i][j] += zg[ii][jj]/(d*d); dist += d; } } } if (dist != 0.) zg[i][j] /= dist; else zg[i][j] = zmin; } } } } plMinMax2dGrid(zg, xp, yp, &lzM, &lzm); plcol0(1); pladv(alg); if (k == 0) { lzm = MIN(lzm, zmin); lzM = MAX(lzM, zmax); for (i=0; i<nl; i++) clev[i] = lzm + (lzM-lzm)/(nl-1)*i; plenv0(xm, xM, ym, yM, 2, 0); plcol0(15); pllab(xlab, ylab, title[alg-1]); plshades(zg, xp, yp, NULL, xm, xM, ym, yM, clev, nl, 1, 0, 1, plfill, 1, NULL, NULL); plcol0(2); } else { for (i=0; i<nl; i++) clev[i] = lzm + (lzM-lzm)/(nl-1)*i; cmap1_init(); plvpor(0.0, 1.0, 0.0, 0.9); plwind(-1.0, 1.0, -1.0, 1.5); /* * For the comparition to be fair, all plots should have the * same z values, but to get the max/min of the data generated * by all algorithms would imply two passes. Keep it simple. * * plw3d(1., 1., 1., xm, xM, ym, yM, zmin, zmax, 30, -60); */ plw3d(1., 1., 1., xm, xM, ym, yM, lzm, lzM, 30, -60); plbox3("bnstu", ylab, 0.0, 0, "bnstu", xlab, 0.0, 0, "bcdmnstuv", "", 0.0, 4); plcol0(15); pllab("", "", title[alg-1]); plot3dc(xg, yg, zg, xp, yp, DRAW_LINEXY | MAG_COLOR | BASE_CONT, clev, nl); } } } plend(); free_data(x, y, z); free_grid(xg, yg); free((void *)clev); plFree2dGrid(zg, xp, yp); }
int main(int argc, char *argv[]) { /* ============== Begin variable definition section. ============= */ /* * i, j, and k are counting variables used in loops and such. M is the * number of lines to be plotted and N is the number of sample points * for each line. */ int i, j, k, M, N, leglen; /* * x is a pointer to an array containing the N x-coordinate values. y * points to an array of M pointers each of which points to an array * containing the N y-coordinate values for that line. */ PLFLT *x, **y; /* Define storage for the min and max values of the data. */ PLFLT xmin, xmax, ymin, ymax, xdiff, ydiff; /* Define storage for the filename and define the input file pointer. */ char filename[80], string[80], tmpstr[80]; FILE *datafile; /* Here are the character strings that appear in the plot legend. */ static char *legend[] = { "Aardvarks", "Gnus", "Llamas", NULL}; /* Make sure last element is NULL */ /* ============== Read in data from input file. ============= */ /* Parse and process command line arguments */ (void) plparseopts(&argc, argv, PL_PARSE_FULL); /* First prompt the user for the input data file name */ printf("Enter input data file name. "); scanf("%s", filename); /* and open the file. */ datafile = fopen(filename, "r"); if (datafile == NULL) /* error opening input file */ error("Error opening input file."); /* Read in values of M and N */ k = fscanf(datafile, "%d %d", &M, &N); if (k != 2) /* something's wrong */ error("Error while reading data file."); /* Allocate memory for all the arrays. */ x = (PLFLT *) malloc(N * sizeof(PLFLT)); if (x == NULL) error("Out of memory!"); y = (PLFLT **) malloc(M * sizeof(PLFLT *)); if (y == NULL) error("Out of memory!"); for (i = 0; i < M; i++) { y[i] = (PLFLT *) malloc(N * sizeof(PLFLT)); if (y[i] == NULL) error("Out of memory!"); } /* Now read in all the data. */ for (i = 0; i < N; i++) { /* N points */ k = fscanf(datafile, "%f", &x[i]); if (k != 1) error("Error while reading data file."); for (j = 0; j < M; j++) { /* M lines */ k = fscanf(datafile, "%f", &y[j][i]); if (k != 1) error("Error while reading data file."); } } /* ============== Graph the data. ============= */ /* Set graph to portrait orientation. (Default is landscape.) */ /* (Portrait is usually desired for inclusion in TeX documents.) */ plsori(1); /* Initialize plplot */ plinit(); /* * We must call pladv() to advance to the first (and only) subpage. * You might want to use plenv() instead of the pladv(), plvpor(), * plwind() sequence. */ pladv(0); /* * Set up the viewport. This is the window into which the data is * plotted. The size of the window can be set with a call to * plvpor(), which sets the size in terms of normalized subpage * coordinates. I want to plot the lines on the upper half of the * page and I want to leave room to the right of the figure for * labelling the lines. We must also leave room for the title and * labels with plvpor(). Normally a call to plvsta() can be used * instead. */ plvpor(0.15, 0.70, 0.5, 0.9); /* * We now need to define the size of the window in user coordinates. * To do this, we first need to determine the range of the data * values. */ xmin = xmax = x[0]; ymin = ymax = y[0][0]; for (i = 0; i < N; i++) { if (x[i] < xmin) xmin = x[i]; if (x[i] > xmax) xmax = x[i]; for (j = 0; j < M; j++) { if (y[j][i] < ymin) ymin = y[j][i]; if (y[j][i] > ymax) ymax = y[j][i]; } } /* * Now set the size of the window. Leave a small border around the * data. */ xdiff = (xmax - xmin) / 20.; ydiff = (ymax - ymin) / 20.; plwind(xmin - xdiff, xmax + xdiff, ymin - ydiff, ymax + ydiff); /* * Call plbox() to draw the axes (see the PLPLOT manual for * information about the option strings.) */ plbox("bcnst", 0.0, 0, "bcnstv", 0.0, 0); /* * Label the axes and title the graph. The string "#gm" plots the * Greek letter mu, all the Greek letters are available, see the * PLplot manual. */ pllab("Time (weeks)", "Height (#gmparsecs)", "Specimen Growth Rate"); /* * Plot the data. plpoin() draws a symbol at each point. plline() * connects all the points. */ for (i = 0; i < M; i++) { plpoin(N, x, y[i], i + OFFSET); plline(N, x, y[i]); } /* * Draw legend to the right of the chart. Things get a little messy * here. You may want to remove this section if you don't want a * legend drawn. First find length of longest string. */ leglen = 0; for (i = 0; i < M; i++) { if (legend[i] == NULL) break; j = strlen(legend[i]); if (j > leglen) leglen = j; } /* * Now build the string. The string consists of an element from the * legend string array, padded with spaces, followed by one of the * symbols used in plpoin above. */ for (i = 0; i < M; i++) { if (legend[i] == NULL) break; strcpy(string, legend[i]); j = strlen(string); if (j < leglen) { /* pad string with spaces */ for (k = j; k < leglen; k++) string[k] = ' '; string[k] = '\0'; } /* pad an extra space */ strcat(string, " "); j = strlen(string); /* insert the ASCII value of the symbol plotted with plpoin() */ string[j] = i + OFFSET; string[j + 1] = '\0'; /* plot the string */ plmtex("rv", 1., 1. - (double) (i + 1) / (M + 1), 0., string); } /* Tell plplot we are done with this page. */ pladv(0); /* advance page */ /* Don't forget to call plend() to finish off! */ plend(); exit(0); }
int main( int argc, const char *argv[] ) { int i, j, k; PLFLT *x, *y, **z, *z_row_major, *z_col_major; PLFLT dx = 2. / (PLFLT) ( XPTS - 1 ); PLFLT dy = 2. / (PLFLT) ( YPTS - 1 ); PLfGrid2 grid_c, grid_row_major, grid_col_major; PLFLT xx, yy, r; PLINT ifshade; PLFLT zmin, zmax, step; PLFLT clevel[LEVELS]; PLINT nlevel = LEVELS; PLINT indexxmin = 0; PLINT indexxmax = XPTS; PLINT *indexymin; PLINT *indexymax; PLFLT **zlimited; // parameters of ellipse (in x, y index coordinates) that limits the data. // x0, y0 correspond to the exact floating point centre of the index // range. PLFLT x0 = 0.5 * (PLFLT) ( XPTS - 1 ); PLFLT a = 0.9 * x0; PLFLT y0 = 0.5 * (PLFLT) ( YPTS - 1 ); PLFLT b = 0.7 * y0; PLFLT square_root; // Parse and process command line arguments plMergeOpts( options, "x08c options", NULL ); (void) plparseopts( &argc, argv, PL_PARSE_FULL ); // Initialize plplot plinit(); // Allocate data structures x = (PLFLT *) calloc( XPTS, sizeof ( PLFLT ) ); y = (PLFLT *) calloc( YPTS, sizeof ( PLFLT ) ); plAlloc2dGrid( &z, XPTS, YPTS ); z_row_major = (PLFLT *) malloc( XPTS * YPTS * sizeof ( PLFLT ) ); z_col_major = (PLFLT *) malloc( XPTS * YPTS * sizeof ( PLFLT ) ); if ( !z_row_major || !z_col_major ) plexit( "Memory allocation error" ); grid_c.f = z; grid_row_major.f = (PLFLT **) z_row_major; grid_col_major.f = (PLFLT **) z_col_major; grid_c.nx = grid_row_major.nx = grid_col_major.nx = XPTS; grid_c.ny = grid_row_major.ny = grid_col_major.ny = YPTS; for ( i = 0; i < XPTS; i++ ) { x[i] = -1. + (PLFLT) i * dx; if ( rosen ) x[i] *= 1.5; } for ( j = 0; j < YPTS; j++ ) { y[j] = -1. + (PLFLT) j * dy; if ( rosen ) y[j] += 0.5; } for ( i = 0; i < XPTS; i++ ) { xx = x[i]; for ( j = 0; j < YPTS; j++ ) { yy = y[j]; if ( rosen ) { z[i][j] = pow( 1. - xx, 2. ) + 100. * pow( yy - pow( xx, 2. ), 2. ); // The log argument might be zero for just the right grid. if ( z[i][j] > 0. ) z[i][j] = log( z[i][j] ); else z[i][j] = -5.; // -MAXFLOAT would mess-up up the scale } else { r = sqrt( xx * xx + yy * yy ); z[i][j] = exp( -r * r ) * cos( 2.0 * M_PI * r ); } z_row_major[i * YPTS + j] = z[i][j]; z_col_major[i + XPTS * j] = z[i][j]; } } // Allocate and calculate y index ranges and corresponding zlimited. plAlloc2dGrid( &zlimited, XPTS, YPTS ); indexymin = (PLINT *) malloc( XPTS * sizeof ( PLINT ) ); indexymax = (PLINT *) malloc( XPTS * sizeof ( PLINT ) ); if ( !indexymin || !indexymax ) plexit( "Memory allocation error" ); //printf("XPTS = %d\n", XPTS); //printf("x0 = %f\n", x0); //printf("a = %f\n", a); //printf("YPTS = %d\n", YPTS); //printf("y0 = %f\n", y0); //printf("b = %f\n", b); // These values should all be ignored because of the i index range. #if 0 for ( i = 0; i < indexxmin; i++ ) { indexymin[i] = 0; indexymax[i] = YPTS; for ( j = indexymin[i]; j < indexymax[i]; j++ ) // Mark with large value to check this is ignored. zlimited[i][j] = 1.e300; } #endif for ( i = indexxmin; i < indexxmax; i++ ) { square_root = sqrt( 1. - MIN( 1., pow( ( (PLFLT) i - x0 ) / a, 2. ) ) ); // Add 0.5 to find nearest integer and therefore preserve symmetry // with regard to lower and upper bound of y range. indexymin[i] = MAX( 0, (PLINT) ( 0.5 + y0 - b * square_root ) ); // indexymax calculated with the convention that it is 1 // greater than highest valid index. indexymax[i] = MIN( YPTS, 1 + (PLINT) ( 0.5 + y0 + b * square_root ) ); //printf("i, b*square_root, indexymin[i], YPTS - indexymax[i] = %d, %e, %d, %d\n", i, b*square_root, indexymin[i], YPTS - indexymax[i]); #if 0 // These values should all be ignored because of the j index range. for ( j = 0; j < indexymin[i]; j++ ) // Mark with large value to check this is ignored. zlimited[i][j] = 1.e300; #endif for ( j = indexymin[i]; j < indexymax[i]; j++ ) zlimited[i][j] = z[i][j]; #if 0 // These values should all be ignored because of the j index range. for ( j = indexymax[i]; j < YPTS; j++ ) // Mark with large value to check this is ignored. zlimited[i][j] = 1.e300; #endif } #if 0 // These values should all be ignored because of the i index range. for ( i = indexxmax; i < XPTS; i++ ) { indexymin[i] = 0; indexymax[i] = YPTS; for ( j = indexymin[i]; j < indexymax[i]; j++ ) // Mark with large value to check this is ignored. zlimited[i][j] = 1.e300; } #endif plMinMax2dGrid( (const PLFLT * const *) z, XPTS, YPTS, &zmax, &zmin ); step = ( zmax - zmin ) / ( nlevel + 1 ); for ( i = 0; i < nlevel; i++ ) clevel[i] = zmin + step + step * i; pllightsource( 1., 1., 1. ); for ( k = 0; k < 2; k++ ) { for ( ifshade = 0; ifshade < 5; ifshade++ ) { pladv( 0 ); plvpor( 0.0, 1.0, 0.0, 0.9 ); plwind( -1.0, 1.0, -0.9, 1.1 ); plcol0( 3 ); plmtex( "t", 1.0, 0.5, 0.5, title[k] ); plcol0( 1 ); if ( rosen ) plw3d( 1.0, 1.0, 1.0, -1.5, 1.5, -0.5, 1.5, zmin, zmax, alt[k], az[k] ); else plw3d( 1.0, 1.0, 1.0, -1.0, 1.0, -1.0, 1.0, zmin, zmax, alt[k], az[k] ); plbox3( "bnstu", "x axis", 0.0, 0, "bnstu", "y axis", 0.0, 0, "bcdmnstuv", "z axis", 0.0, 0 ); plcol0( 2 ); if ( ifshade == 0 ) // diffuse light surface plot { cmap1_init( 1 ); plfsurf3d( x, y, plf2ops_c(), (PLPointer) z, XPTS, YPTS, 0, NULL, 0 ); } else if ( ifshade == 1 ) // magnitude colored plot { cmap1_init( 0 ); plfsurf3d( x, y, plf2ops_grid_c(), ( PLPointer ) & grid_c, XPTS, YPTS, MAG_COLOR, NULL, 0 ); } else if ( ifshade == 2 ) // magnitude colored plot with faceted squares { cmap1_init( 0 ); plfsurf3d( x, y, plf2ops_grid_row_major(), ( PLPointer ) & grid_row_major, XPTS, YPTS, MAG_COLOR | FACETED, NULL, 0 ); } else if ( ifshade == 3 ) // magnitude colored plot with contours { cmap1_init( 0 ); plfsurf3d( x, y, plf2ops_grid_col_major(), ( PLPointer ) & grid_col_major, XPTS, YPTS, MAG_COLOR | SURF_CONT | BASE_CONT, clevel, nlevel ); } else // magnitude colored plot with contours and index limits. { cmap1_init( 0 ); plsurf3dl( x, y, (const PLFLT * const *) zlimited, XPTS, YPTS, MAG_COLOR | SURF_CONT | BASE_CONT, clevel, nlevel, indexxmin, indexxmax, indexymin, indexymax ); } } } // Clean up free( (void *) x ); free( (void *) y ); plFree2dGrid( z, XPTS, YPTS ); free( (void *) z_row_major ); free( (void *) z_col_major ); plFree2dGrid( zlimited, XPTS, YPTS ); free( (void *) indexymin ); free( (void *) indexymax ); plend(); exit( 0 ); }
int main( int argc, const char *argv[] ) { char text[10]; int i, j, k, l; PLFLT x, y; // Parse and process command line arguments (void) plparseopts( &argc, argv, PL_PARSE_FULL ); // Initialize plplot plinit(); plfontld( 0 ); for ( l = 0; l < 20; l++ ) { if ( l == 2 ) plfontld( 1 ); pladv( 0 ); // Set up viewport and window plcol0( 2 ); plvpor( 0.15, 0.95, 0.1, 0.9 ); plwind( 0.0, 1.0, 0.0, 1.0 ); // Draw the grid using plbox plbox( "bcg", 0.1, 0, "bcg", 0.1, 0 ); // Write the digits below the frame plcol0( 15 ); for ( i = 0; i <= 9; i++ ) { sprintf( text, "%d", i ); plmtex( "b", 1.5, ( 0.1 * i + 0.05 ), 0.5, text ); } k = 0; for ( i = 0; i <= 9; i++ ) { // Write the digits to the left of the frame sprintf( text, "%d", base[l] + 10 * i ); plmtex( "lv", 1.0, ( 0.95 - 0.1 * i ), 1.0, text ); for ( j = 0; j <= 9; j++ ) { x = 0.1 * j + 0.05; y = 0.95 - 0.1 * i; // Display the symbols plsym( 1, &x, &y, base[l] + k ); k = k + 1; } } if ( l < 2 ) plmtex( "t", 1.5, 0.5, 0.5, "PLplot Example 7 - PLSYM symbols (compact)" ); else plmtex( "t", 1.5, 0.5, 0.5, "PLplot Example 7 - PLSYM symbols (extended)" ); } plend(); exit( 0 ); }
void plotall(int nlyr, double* T, double* plyr, double* z, double* deltaTday) { #ifndef _NOPLOT /* Plot T against p */ pladv(1); /* select subpage 1 */ plvsta(); /* standard viewport */ plclear(); /* clear subpage */ plcol0 (15); /* color black */ plwind( 0, 400, PSURF, 0 ); /* xmin, xmax, ymin, ymax */ plbox( "bcnst", 100, 0, "bcnst", 150.0, 0 ); pllab ("temperature [K]", "p [hPa]", ""); /* axis labels */ plcol0 (14); /* color blue */ plline (nlyr, T, plyr); /* plot temperature profile */ plcol0 (15); /* color black */ /* Plot T against z */ pladv(3); /* select subpage 1 */ plvsta(); /* standard viewport */ plclear(); /* clear subpage */ plcol0 (15); /* color black */ plwind( 0, 400, 0, 40000 ); /* xmin, xmax, ymin, ymax */ plbox( "bcnst", 100, 0, "bcnst", 5000.0, 0 ); pllab ("temperature [K]", "z [m]", ""); /* axis labels */ plcol0 (14); /* color blue */ plline (nlyr, T, z); /* plot temperature profile */ plcol0 (15); /* color black */ /* Plot Heating rate against p */ pladv(2); /* select subpage 1 */ plvsta(); /* standard viewport */ plclear(); /* clear subpage */ plcol0 (15); /* color black */ plwind( -20, 20, PSURF, 0 ); /* xmin, xmax, ymin, ymax */ plbox( "bcnst", 2, 0, "bcnst", 150.0, 0 ); pllab ("Heating Rate [T/day]", "p [hPa]", ""); /* axis labels */ plcol0 (12); /* color blue */ plline (nlyr, deltaTday, plyr); /* plot temperature profile */ plcol0 (15); /* color black */ /* Plot Heating rate against z */ pladv(4); /* select subpage 1 */ plvsta(); /* standard viewport */ plclear(); /* clear subpage */ plcol0 (15); /* color black */ plwind( -20, 20, 0, 40000 ); /* xmin, xmax, ymin, ymax */ plbox( "bcnst", 2, 0, "bcnst", 5000.0, 0 ); pllab ("Heating Rate [T/day]", "z [m]", ""); /* axis labels */ plcol0 (12); /* color blue */ plline (nlyr, deltaTday, z); /* plot temperature profile */ plcol0 (15); /* color black */ #endif }