static plplot_state_type * plplot_state_alloc( const void * init_arg ) { plplot_state_type * state = util_malloc( sizeof * state ); state->stream = 0; { const arg_pack_type * arg_pack = arg_pack_safe_cast_const( init_arg ); state->filename = util_alloc_string_copy( arg_pack_iget_const_ptr( arg_pack , 0) ); state->device = util_alloc_string_copy( arg_pack_iget_const_ptr( arg_pack , 1) ); plsstrm(state->stream); plsdev(state->device); /* Can this be NULL?? */ if (strcmp(state->device , "xwin") != 0) plsfnam(state->filename); } state->logx = false; state->logy = false; state->plbox_xopt = util_alloc_string_copy( PLOT_DEFAULT_PLBOX_XOPT ); state->plbox_yopt = util_alloc_string_copy( PLOT_DEFAULT_PLBOX_YOPT ); /** This color initialization must be here - do not really understand what for. */ plscol0(WHITE, 255, 255, 255); plscol0(BLACK, 0, 0, 0); plfontld(0); //plinit(); return state; }
int main( int argc, char *argv[] ) { PLINT digmax, cur_strm, new_strm; char ver[80]; // plplot initialization // Parse and process command line arguments plMergeOpts( options, "x01c options", notes ); plparseopts( &argc, argv, PL_PARSE_FULL ); // Get version number, just for kicks plgver( ver ); fprintf( stdout, "PLplot library version: %s\n", ver ); // Initialize plplot // Divide page into 2x2 plots // Note: calling plstar replaces separate calls to plssub and plinit plstar( 2, 2 ); // Select font set as per input flag if ( fontset ) plfontld( 1 ); else plfontld( 0 ); // Set up the data // Original case xscale = 6.; yscale = 1.; xoff = 0.; yoff = 0.; // Do a plot plot1( 0 ); // Set up the data xscale = 1.; yscale = 0.0014; yoff = 0.0185; // Do a plot digmax = 5; plsyax( digmax, 0 ); plot1( 1 ); plot2(); plot3(); // // Show how to save a plot: // Open a new device, make it current, copy parameters, // and replay the plot buffer // if ( f_name ) // command line option '-save filename' { printf( "The current plot was saved in color Postscript under the name `%s'.\n", f_name ); plgstrm( &cur_strm ); // get current stream plmkstrm( &new_strm ); // create a new one plsfnam( f_name ); // file name plsdev( "psc" ); // device type plcpstrm( cur_strm, 0 ); // copy old stream parameters to new stream plreplot(); // do the save by replaying the plot buffer plend1(); // finish the device plsstrm( cur_strm ); // return to previous stream } // Let's get some user input if ( locate_mode ) { for (;; ) { if ( !plGetCursor( &gin ) ) break; if ( gin.keysym == PLK_Escape ) break; pltext(); printf( "subwin = %d, wx = %f, wy = %f, dx = %f, dy = %f\n", gin.subwindow, gin.wX, gin.wY, gin.dX, gin.dY ); printf( "keysym = 0x%02x, button = 0x%02x, string = '%s', type = 0x%02x, state = 0x%02x\n", gin.keysym, gin.button, gin.string, gin.type, gin.state ); plgra(); } } // Don't forget to call plend() to finish off! plend(); exit( 0 ); }
void canopy::plot() { double max = haz[0]; for(int i=0; i<numNodes; i++) { if(haz[i]>max) max = haz[i]; } printf("max = %lf\n", max); // PLFLT xmin =0, ymin=0, xmax=1, ymax=1, // x[6]= {0.0, 1.0, 2.0, 3.0, 4.0, 5.0}, // y[6] = {0., 1.0, 4.0, 9.1, 15.5, 25.3}; double* y = new double[numNodes]; for(int i=0; i<numNodes; i++) { y[i] = i*cellsize; } double* x = new double[numNodes]; for(int i=0; i<numNodes; i++) { //---------------FIX THIS------------------!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! //x[i] = haz[i]/max; x[i] = haz[i]; //---------------FIX THIS------------------!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! if(i%100 == 0) printf("%lf\t%lf\n",x[i], y[i]); } PLFLT xmin =0, ymin=0, xmax=0.001, ymax=1; PLINT just=0, axis=0; plstream *pls; // plplot initialization pls = new plstream(); // declare plplot object //plsdev("wxwidgets"); // sets the plot device to WX Widget which // allows for viewing and saving the plot to a file // Note that saving postscript from within widgets is buggy. // other useful values in place of wxwidgets: // xwin - X-window display to screen // ps - postscript file // psc - color postscript file // Or just comment out line to get a list of choices //plsdev("psc"); plsdev("pdf"); //cairo uses the same color scheme as on screen - black on //red on black default plsfnam("haz.pdf");// sets the names of the output file // Parse and process command line arguments. //pls->parseopts( &argc, argv, PL_PARSE_FULL ); // device and other options // can be set from the command-line: // -dev devname sets the output device to "devname" // -o output_file sets the output file name to output_file // -h gives a list of all possible options pls->init(); // start plplot object pls->env(xmin, xmax, ymin, ymax, just, axis ); //Setup window size // - just=0 sets axis so they scale indepedently // - axis=0 draw axis box, ticks, and numeric labels // see "man plenv" for details pls->lab( "haz/max", "z/h", "haz plot"); // Plot the data points - (num_points, x, y. plot_symbol) // - plot_symbol=9 sets a circle with a dot in the // middle for the plot symbol - see "man plpoin" //pls->poin( numNodes, (PLFLT*) x,(PLFLT*) y, 9 ); pls->line( numNodes, (PLFLT*) x,(PLFLT*) y); delete pls; // close plot delete x; x = NULL; delete y; y = NULL; }
/* * Plot specified x/y coordinates, x as int32_t and y as float, with an arbitrary number * of separate lines, as lines and/or points. * Output is PDF file, location specified by 'fileName'. */ int plplotLines( PlplotSetup *setup, uint32_t numSamples, /* size of ix[] and fy[] arrays */ uint32_t numLines, /* size of lineDef[] array */ int32_t *ix, /* numSamples */ LineDef *lineDef, /* numLines */ const char *graphName, const char *fileName, bool plotPoints, /* true: plot points */ bool plotLine, /* true: plot line */ bool skipTrailZeroes) /* don't plot zero Y values at end of graph */ { if(setup == NULL) { printf("***plplotLine: setup required\n"); return -1; } char tmpFile[TEMP_FN_LEN]; makeTempFile(tmpFile, TEMP_FN_LEN); PLFLT fx[numSamples]; PLFLT minX = setup->minX; PLFLT maxX = setup->maxX; PLFLT minY = setup->minY; PLFLT maxY = setup->maxY; for(uint32_t dex=0; dex<numSamples; dex++) { fx[dex] = ix[dex]; } const char *yName = ""; if(setup->yAxisName) { yName = setup->yAxisName; } const char *xName = ""; if(setup->xAxisName) { xName = setup->xAxisName; } plsdev ("psc"); /* standard: background white, foreground (axes, labels, etc.) black */ plscolbg(PLOT_WHITE); plscol0(1, PLOT_BLACK); plsfnam(tmpFile); plsdiori(1.0); // portrait plinit(); plenv(minX, maxX, minY, maxY, 0, 0); pllab(xName, yName, graphName); for(uint32_t dex=0; dex<numLines; dex++) { uint32_t thisSamples = numSamples; if(skipTrailZeroes) { while((lineDef[dex].fy[thisSamples-1] == 0.0) && (thisSamples > 0)) { thisSamples--; } if(thisSamples == 0) { printf("***plplotLines: Warning: line with all zeroes skipped\n"); continue; } } plotOneLine(thisSamples, fx, &lineDef[dex], plotPoints, plotLine); } plend(); int ourRtn = psToPdf(tmpFile, fileName); unlink(tmpFile); return ourRtn; }
/* * Plot a histogram of prebinned data. X values are int32_t's, and the corresponding * Y values - the counts for each X - are uint32_t's. */ int plplotBins( uint32_t numBins, const int32_t *x, /* numBins of X values, monotonically increasing */ const uint32_t *y, /* numBins of Y values for each associated X */ const char *graphName, const char *fileName, const char *xAxisName, /* optional */ const char *yAxisName) /* optional */ { char tmpFile[TEMP_FN_LEN]; makeTempFile(tmpFile, TEMP_FN_LEN); PLINT totalBins = numBins + 2; /* PLFLT array of sample values */ PLFLT *xf = (PLFLT *)malloc(totalBins * sizeof(PLFLT)); /* these two will have Y values of zero */ xf[0] = x[0] - 1; xf[totalBins - 1] = x[numBins-1] + 1; const int32_t *ip = x; PLFLT *op = xf + 1; for(uint32_t dex=0; dex<numBins; dex++) { *op++ = *ip++; } /* PLFLT array of bins */ PLFLT *yf = (PLFLT *)malloc(totalBins * sizeof(PLFLT)); yf[0] = 0.0; yf[totalBins - 1] = 0.0; const uint32_t *uip = y; op = yf + 1; for(uint32_t dex=0; dex<numBins; dex++) { *op++ = *uip++; } /* get max Y value */ uint32_t maxY = 0; uip = y; for(uint32_t dex=0; dex<numBins; dex++) { uint32_t currY = *uip++; if(currY > maxY) { maxY = currY; } } const char *yName = yAxisName ? yAxisName : ""; const char *xName = xAxisName ? xAxisName : ""; #if HIST_COLOR plsdev ("psc"); plscolbg(255, 255, 255); /* white background */ #else plsdev ("ps"); #endif plsfnam(tmpFile); plsdiori(1.0); // portrait plinit(); plenv(xf[0], xf[totalBins - 1], 0, maxY, 0, 0); #if HIST_COLOR /* can we alter colors of lines and the spaces inside the histograms? */ plscolbg(255, 0, 0); /* red background */ plscol0(1, 255, 0, 0); /* red foreground - no effect */ #endif pllab(xName, yName, graphName); plbin(totalBins, xf, yf, PL_BIN_CENTRED); plend(); free(xf); free(yf); int ourRtn = psToPdf(tmpFile, fileName); unlink(tmpFile); return ourRtn; }
/* * Plot a histogram showing the number of occurences of each possible * value of 'samples'. */ int plplotHist( const int32_t *samples, uint32_t numSamples, const char *graphName, const char *fileName, const char *xAxisName, /* optional */ const char *yAxisName) /* optional */ { char tmpFile[TEMP_FN_LEN]; makeTempFile(tmpFile, TEMP_FN_LEN); /* First determine the range, i.e. the number of bins */ int32_t minSamp = samples[0]; int32_t maxSamp = samples[0]; for(uint32_t dex=0; dex<numSamples; dex++) { int32_t s = samples[dex]; if(s < minSamp) { minSamp = s; } if(s > maxSamp) { maxSamp = s; } } /* When we specify PL_BIN_CENTRED, the min and max values are half the normal width */ minSamp--; maxSamp++; PLINT numBins = maxSamp - minSamp + 1; /* One array containing the sample values, x */ PLFLT *x = (PLFLT *)malloc(numBins * sizeof(PLFLT)); int32_t binNum = minSamp; for(uint32_t dex=0; dex<(uint32_t)numBins; dex++) { x[dex] = binNum++; } /* Now make and fill the bins proper */ PLFLT *y = (PLFLT *)malloc(numBins * sizeof(PLFLT)); for(uint32_t dex=0; dex<(uint32_t)numBins; dex++) { y[dex] = 0; } PLFLT maxY = 0.0; for(uint32_t dex=0; dex<numSamples; dex++) { int32_t s = samples[dex]; PLFLT *yp = y + s - minSamp; *yp += 1.0; if(*yp > maxY) { maxY = *yp; } } const char *yName = yAxisName ? yAxisName : ""; const char *xName = xAxisName ? xAxisName : ""; #if HIST_COLOR plsdev ("psc"); plscolor(1); plscolbg(255, 255, 255); /* white background */ #else plsdev ("ps"); #endif plsfnam(tmpFile); plsdiori(1.0); // portrait plinit(); plenv(minSamp, maxSamp, 0, maxY, 0, 0); #if HIST_COLOR /* can we alter colors of lines and the spaces inside the histograms? */ plscolbg(255, 0, 0); /* red background */ plscol0(1, 255, 0, 0); /* red foreground - no effect */ #endif pllab(xName, yName, graphName); plbin(numBins, x, y, PL_BIN_CENTRED); plend(); free(x); free(y); int ourRtn = psToPdf(tmpFile, fileName); unlink(tmpFile); return ourRtn; }