void draw_polygons(struct polygon* polygons, int number_of_polygons,int delay){ if(h==0){ h = gnuplot_init(); gnuplot_cmd(h, "clear"); gnuplot_cmd(h,"reset"); //gnuplot_cmd(h,"set terminal gif animate "); //gnuplot_cmd(h,"set output \"animate.gif\""); gnuplot_cmd(h,"set terminal gif small animate delay 7"); gnuplot_cmd(h,"set output \"animate.gif\""); gnuplot_cmd(h, "set isosample 40" ); gnuplot_cmd(h, "set xrange [-5:5]"); gnuplot_cmd(h, "set yrange [-5:5]"); puts("Initiating polygon drawing\n"); } int i,j; gnuplot_cmd(h,"unset arrow"); gnuplot_cmd(h, "set style arrow 1 nohead") ; for(j=0;j<number_of_polygons;j++){ for(i=0;i<polygons[j].numberOfVertices-1;i++){ gnuplot_resetplot(h); gnuplot_cmd(h, "set arrow from %f,%f to %f,%f as 1",polygons[j].x_list[i], polygons[j].y_list[i],polygons[j].x_list[i+1], polygons[j].y_list[i+1]); } } gnuplot_cmd(h, "plot[-5:5][-5:5] NaN notitle"); gnuplot_cmd(h,"set size square"); mysleep(delay); }
int main(int arg, char *argv[]) { int Npoint, dec, line, Nline, sector; double x0, xf; //socket variable SOCKET sock; const char *IP="192.168.128.3"; init_TCP_client(&sock, IP, Port); int Nset=5; char settings[Nset]; receive_TCP_client(&sock, settings, Nset); x0=(double)int_converter(settings[0]); xf=(double)int_converter(settings[1]); dec=int_converter(settings[2]); line=int_converter(settings[3]); Nline=line/2; sector=int_converter(settings[4]); Npoint=(int)(2.0*(xf-x0)*125.0/1.48/((double)dec)); char *buff=(char *)malloc((Npoint+1)*sizeof(char)); //gnuplot variable gnuplot_ctrl * h; double *y= (double *)malloc(Npoint*sizeof(double)); int i,j; //gnuplot object h=gnuplot_init(); gnuplot_setstyle(h,"lines"); gnuplot_set_xlabel(h,"time (us)"); gnuplot_set_ylabel(h,"signal"); gnuplot_cmd(h,"set yrange [1:%d]",Ymax); gnuplot_cmd(h,"set xrange [0:%d]",Npoint-1); while(1) { if (receive_TCP_client(&sock, buff, Npoint+1)==1) { break; } if ((int)(buff[0])==Nline) { for (i=1; i<Npoint+1 ; i++) { y[i-1]=(double)(buff[i]); } gnuplot_resetplot(h); gnuplot_plot_x(h, y, Npoint, "RP"); } } usleep(30); close(sock); free(y); return 0; }
void draw_adjTable( unsigned int cs_size,double **cs,unsigned int* atArr,unsigned int **at,double connectRad,long int delay){ int i,j; if(h==0){ h = gnuplot_init(); gnuplot_cmd(h, "clear"); gnuplot_cmd(h,"reset"); // gnuplot_cmd(h,"set terminal gif small animate delay 1 optimize"); // gnuplot_cmd(h,"set output \"animate.gif\""); // gnuplot_cmd(h,"set terminal postscript eps enhanced color font 'Helvetica,10'"); // gnuplot_cmd(h,"set output \"plot1.eps\""); gnuplot_cmd(h,"set terminal epslatex size 3.5,2.62 color colortext"); gnuplot_cmd(h,"set output 'introduction.tex'"); // gnuplot_cmd(h, "set xrange [-4:4]"); // gnuplot_cmd(h, "set yrange [-4:4]"); // gnuplot_cmd(h, "set zrange [-4:4]"); // gnuplot_cmd(h, "set xlabel \"theta_1\" "); // gnuplot_cmd(h, "set ylabel \"theta_2\" "); // gnuplot_cmd(h, "set zlabel \"theta_3\" "); gnuplot_cmd(h, "set isosample 40" ); } gnuplot_resetplot(h); gnuplot_cmd(h,"set multiplot"); double tol=connectRad ; gnuplot_cmd(h,"splot [-3.2:3.2][-3.2:3.2][-3.2:3.2] \"-\" using 1:2:3 with points pointtype 26 ps 0.6 notitle "); for(i=0;i<cs_size;i++){ gnuplot_cmd(h,"%f %f %f", cs[i][0], cs[i][1], cs[i][2]); } gnuplot_cmd(h,"e"); gnuplot_cmd(h, "set xlabel \"theta_1\" ") ; gnuplot_cmd(h, "set ylabel \"theta_2\" ") ; gnuplot_cmd(h, "set zlabel \"theta_3\" ") ; gnuplot_cmd(h, "set style arrow 1 nohead") ; int temp; for(i=0;i<cs_size;i++){ for(j=0;j<atArr[i];j++){ temp=at[i][j]; if( fabs(cs[i][0]-cs[temp][0])>tol ||fabs(cs[i][1]-cs[temp][1])>tol ||fabs(cs[i][2]-cs[temp][2])>tol){ // do nothing }else{ gnuplot_cmd(h, "set arrow from %f,%f,%f to %f,%f,%f as 1",cs[i][0],cs[i][1], cs[i][2],cs[temp][0],cs[temp][1], cs[temp][2]); mysleep(delay); gnuplot_cmd(h,"splot[-3.2:3.2][-3.2:3.2][-3.2:3.2] NaN notitle"); } } } mysleep(delay); // gnuplot_cmd(h,"unset multiplot"); }
int plot_doubles(gnuplot_ctrl *h, double *xdata, double *ydata, int len, char *plot_name) { if( h == NULL || ydata == NULL || xdata == NULL|| len <= 0 || plot_name == NULL){ fprintf(stderr, "plot_data: dodgy arguments\n"); return -1; } gnuplot_setstyle(h, "lines"); gnuplot_resetplot(h); gnuplot_plot_xy(h, xdata, ydata, len, plot_name); return 0; }
void reinit_graph(gnuplot_ctrl *gc) { static int total = 0; char id = '0'; if (gc == g) id = 'a'; else id = 'b'; gnuplot_resetplot(gc); //gnuplot_cmd(gc, "set terminal svg"); //gnuplot_cmd(gc, "set output \"gnuplot-%c%04d.svg\"", id, total); total++; }
void ParticleListCPUSorted::plot_particles(PlasmaData* pdata) { float* x_vals = (float*)malloc(nptcls*sizeof(realkind)); float* y_vals = (float*)malloc(nptcls*sizeof(realkind)); for(int i=0;i<nptcls;i++) { x_vals[i] = (px[i]+ix[i])*pdata->dxdi + pdata->xmin; //x_vals[i] = (py[i]+iy[i])*pdata->dydi + pdata->ymin; y_vals[i] = vx[i]; // printf("particle[%i]: %f %f\n",i,x_vals[i],y_vals[i]); } gnuplot_resetplot(plot); gnuplot_plot_xy(plot,x_vals,y_vals,nptcls,NULL); free(x_vals); free(y_vals); }
void TwoStream_Initializer::finish(ParticleList* particles, HOMoments** moments,HOMoments* moments_old,FieldData** fields,ParallelInfo* myinfo) { // Print out the sum of the x-component of the current if(myinfo->myid_mpi == 0) { if(pdata->plot_flag) { gnuplot_resetplot(plot); gnuplot_cmd(plot,"set xlabel \"time\""); gnuplot_cmd(plot,"set ylabel \"Field Energy\""); gnuplot_plot_xy(plot,max_t_array,Energy_array,nplot,"PlasmaApp3D"); gnuplot_cmd(plot,"replot \"E_vec.csv\" title \"Matlab Code\" with points"); //getchar(); gnuplot_save_pdf(plot,"TS_field_energy"); } } MPI_Barrier(MPI_COMM_WORLD); }
int main ( int argc, char *argv[] ) /******************************************************************************/ /* Purpose: MAIN is the main program for ANIM. Modified: 24 June 2011 */ { double d[NPOINTS]; dpoint dp[NPOINTS]; gnuplot_ctrl *h1; gnuplot_ctrl *h2; gnuplot_ctrl *h3; gnuplot_ctrl *h4; int i; int j; double x[NPOINTS]; double y[NPOINTS]; printf ( "\n" ); printf ( "EXAMPLE:\n" ); printf ( " C++ version.\n" ); printf ( " Demonstrate how a running C++ program can produce plots\n" ); printf ( " through GNUPLOT, by invoking the GNUPLOT_I interface library.\n" ); /* Initialize the gnuplot handle */ h1 = gnuplot_init(); if ( h1 == NULL ) { printf ( "\n" ); printf ( "EXAMPLE - Fatal error!\n" ); printf ( " GNUPLOT is not available in your path.\n" ); exit ( 1 ); } /* Slopes */ gnuplot_setstyle(h1, "lines"); slow_print("*** plotting slopes\n"); slow_print("y = x\n"); gnuplot_plot_slope(h1, 1.0, 0.0, "unity slope"); sleep(SLEEP_LGTH); slow_print("y = 2*x\n"); gnuplot_plot_slope(h1, 2.0, 0.0, "y=2x"); sleep(SLEEP_LGTH); slow_print("y = -x\n"); gnuplot_plot_slope(h1, -1.0, 0.0, "y=-x"); sleep(SLEEP_LGTH); /* Equations */ gnuplot_resetplot(h1); printf("\n\n"); slow_print("*** various equations\n"); slow_print("y = sin(x)\n"); gnuplot_plot_equation(h1, "sin(x)", "sine"); sleep(SLEEP_LGTH); slow_print("y = log(x)\n"); gnuplot_plot_equation(h1, "log(x)", "logarithm"); sleep(SLEEP_LGTH); slow_print("y = sin(x)*cos(2*x)\n"); gnuplot_plot_equation(h1, "sin(x)*cos(2*x)", "sine product"); sleep(SLEEP_LGTH); /* Styles */ gnuplot_resetplot(h1); printf("\n\n"); slow_print("*** Showing plot style options:\n"); slow_print("sine(x) in points\n"); gnuplot_setstyle(h1, "points"); gnuplot_plot_equation(h1, "sin(x)", "sine"); sleep(SLEEP_LGTH); slow_print("sine(x) in impulses\n"); gnuplot_setstyle(h1, "impulses"); gnuplot_plot_equation(h1, "sin(x)", "sine"); sleep(SLEEP_LGTH); slow_print("sine(x) in steps\n"); gnuplot_setstyle(h1, "steps"); gnuplot_plot_equation(h1, "sin(x)", "sine"); sleep(SLEEP_LGTH); /* User defined 1d and 2d point sets */ gnuplot_resetplot(h1); gnuplot_setstyle(h1, "impulses"); printf("\n\n"); slow_print("*** user defined lists of points\n"); slow_print("random doubles\n"); srand48 ( getpid ( ) ); for ( i = 0; i < NPOINTS; i++ ) { d[i] = drand48(); } gnuplot_plot1d_var1(h1, d, NPOINTS, "random doubles"); sleep(SLEEP_LGTH); gnuplot_resetplot(h1); gnuplot_setstyle(h1, "points"); slow_print("random points\n"); for ( i = 0; i < NPOINTS; i++ ) { dp[i].x = drand48(); dp[i].y = drand48(); } gnuplot_plot1d_var2(h1, dp, NPOINTS, "random points"); sleep(SLEEP_LGTH); gnuplot_resetplot(h1); gnuplot_setstyle(h1, "points"); slow_print("cosine points with var2v\n"); for ( j = 0; j < NPOINTS; j++ ) { x[j] = ( double ) j / 10.0; y[j] = cos ( x[j] ); } gnuplot_plot1d_var2v(h1, x, y, NPOINTS, "cosine points"); sleep(SLEEP_LGTH); /* Multiple output screens */ printf("\n\n"); slow_print("*** multiple output windows\n"); gnuplot_resetplot(h1); gnuplot_setstyle(h1, "lines"); h2 = gnuplot_init(); gnuplot_setstyle(h2, "lines"); h3 = gnuplot_init(); gnuplot_setstyle(h3, "lines"); h4 = gnuplot_init(); gnuplot_setstyle(h4, "lines"); slow_print("window 1: sin(x)\n"); gnuplot_plot_equation(h1, "sin(x)", "sin(x)"); sleep(SLEEP_LGTH); slow_print("window 2: cos(x)\n"); gnuplot_plot_equation(h2, "cos(x)", "cos(x)"); sleep(SLEEP_LGTH); slow_print("window 3: asin(x)\n"); gnuplot_plot_equation(h3, "asin(x)", "arcsin(x)"); sleep(SLEEP_LGTH); slow_print("window 4: acos(x)\n"); gnuplot_plot_equation(h4, "acos(x)", "arccos(x)"); sleep(SLEEP_LGTH); /* Close gnuplot handles. */ printf ( "\n\n" ); slow_print ( "*** end of gnuplot example\n" ); gnuplot_close ( h1 ); gnuplot_close ( h2 ); gnuplot_close ( h3 ); gnuplot_close ( h4 ); /* Terminate. */ printf ( "\n" ); printf ( "EXAMPLE:\n" ); printf ( " Normal end of execution.\n" ); return 0; }
void PlotGraph::PlotBipartiteGraph(BipartiteGraph& _bg, vector<VID>& _S, vector<VID>& _T, vector<VID>& _N, vector<EID>& _EG, vector<EID>& _M, int target_task){ //get assignment size, assume the sizes of agents and tasks are identical size_t as_size = _bg.GetNumAgents(); double plx[as_size]; double ply[as_size]; //g=gnuplot_init(); gnuplot_resetplot(g); gnuplot_cmd(g, (char*)"unset label"); gnuplot_cmd(g, (char*)"set xrange [-0.25:%f]", as_size-1+.25); gnuplot_cmd(g, (char*)"set yrange [-0.25:1.25]"); gnuplot_cmd(g, (char*)"set xtics 0"); gnuplot_cmd(g, (char*)"set ytics 0"); gnuplot_cmd(g, (char*)"set nokey"); // Plot matching //cout<<endl<<"Set M: "<<endl; //DisplayData(_M); for (unsigned int i = 0; i < _M.size(); i++){ plx[0] = _M[i].first; ply[0] = 0.0; plx[1] = _M[i].second; ply[1] = 1.0; gnuplot_setstyle(g, (char*)"lines lc rgb \"red\" lw 3"); gnuplot_plot_xy(g, plx, ply, 2, NULL); } // Plot admissible edges (EG) //cout<<"EG: "<<endl; //DisplayData(_EG); for(unsigned int i=0; i<_EG.size(); i++){ plx[0] = _EG[i].first; ply[0] = 0.0; plx[1] = _EG[i].second; ply[1] = 1.0; gnuplot_setstyle(g, (char*)"lines lc rgb \"gray\""); gnuplot_plot_xy(g, plx, ply, 2, NULL); plx[0] = (0.9*plx[0] + 0.1*plx[1]); ply[0] = 0.11; gnuplot_setstyle(g, (char*)"points pointsize 2 lc rgb \"#FFFFFF\" pt 7"); gnuplot_plot_xy(g, plx, ply, 1, NULL); //cout<<"EG "<<i<<": "<<_bg.GetMatrix(_EG[i])->GetWeight()<<endl; gnuplot_cmd(g, (char*)"set label \"%d\" at %f-0.04,0.1 front tc rgb \"#4682B4\" font \",8\"", int(_bg.GetMatrix(_EG[i])->GetWeight()), plx[0]); } // Plot membership of set S //cout<<"S: "<<endl; //DisplayData(_S); for(unsigned int i=0; i<_S.size(); i++){ plx[0] = _S[i]; ply[0] = 0.0; gnuplot_setstyle(g, (char*)"points pointsize 3 lc rgb \"green\" pt 7"); gnuplot_plot_xy(g, plx, ply, 1, NULL); } // Plot membership of the set T //cout<<"T: "<<endl; //DisplayData(_T); for(unsigned int i=0; i<_T.size(); i++){ plx[0] = _T[i]; ply[0] = 1.0; gnuplot_setstyle(g, (char*)"points pointsize 3 lc rgb \"#00BFFF\" pt 7"); gnuplot_plot_xy(g, plx, ply, 1, NULL); } if (target_task != -1) // not yet unioned, but the reversal point for the { // alternating path plx[0] = target_task; ply[0] = 1.0; gnuplot_setstyle(g, (char*)"points pointsize 3 lc rgb \"grey\" pt 7"); gnuplot_plot_xy(g, plx, ply, 1, NULL); } // Plot nodes for(unsigned int i = 0; i < as_size; i++) { plx[i] = i; ply[i] = 0.0; } gnuplot_setstyle(g, (char*)"points pointsize 2 lc rgb \"#102063\" pt 7"); gnuplot_plot_xy(g, plx, ply, as_size, NULL); for(unsigned int i = 0; i < as_size; i++) { plx[i] = i; ply[i] = 1.0; } gnuplot_setstyle(g, (char*)"points pointsize 2 lc rgb \"#102063\" pt 7"); gnuplot_plot_xy(g, plx, ply, as_size, NULL); for (unsigned int i = 0; i < as_size; i++) { gnuplot_cmd(g, (char*)"set label \"x%d\" at %d-0.025,-0.08 tc rgb \"black\"", i, i); gnuplot_cmd(g, (char*)"set label \"y%d\" at %d-0.025,1.08 tc rgb \"black\"", i, i); //cout<<"Label "<<i<<": "<<_bg.GetAgent(i)->GetLabel()<<endl; //cout<<"Label "<<i<<": "<<_bg.GetTask(i)->GetLabel()<<endl; gnuplot_cmd(g, (char*)"set label \"%d\" at %d-0.025,-0.15 tc rgb \"#112244\"", int(_bg.GetAgent(i)->GetLabel()), i); gnuplot_cmd(g, (char*)"set label \"%d\" at %d-0.025,1.15 tc rgb \"#112244\"", int(_bg.GetTask(i)->GetLabel()), i); } /* //image setting set terminal png {{no}transparent} {{no}interlace} {tiny | small | medium | large | giant} {font <face> {<pointsize>}} {size <x>,<y>} {{no}crop} {{no}enhanced} {<color0> <color1> <color2> ...} */ #ifdef SAVE_PLOTS stringstream ss; ss << setw(3) << setfill('0') << Cnt++; string postfix = ss.str(); string name="save/plot"+postfix+".jpeg"; gnuplot_cmd(g, (char*)"set terminal jpeg"); //gnuplot_cmd(g, (char*)"set terminal jpeg small size 320,240");//bad gnuplot_cmd(g, (char*)"set output \"%s\"", name.c_str()); printf("saved jpeg: \"%s\"\n", name.c_str()); #endif gnuplot_cmd(g, (char*)"replot"); sleep(period); //gnuplot_close(g); }
static void plot(){ gnuplot_resetplot(handle); gnuplot_plot_x(handle, samples, NSAMPLES, ""); }
int main(int arg, char *argv[]) { int Npoint; //socket variable SOCKET sock; const char *IP="192.168.128.3"; init_TCP_client(&sock, IP, Port); get_RP_settings(&sock); printf("r0=%f\n",r0); printf("rf=%f\n",rf); printf("dec=%i\n",dec); printf("Nline=%i\n",Nline); printf("sector=%f\n",sector); printf("mode_RP=%i\n",mode_RP); int l=0; Npoint=(int)(2.0*(rf-r0)*125.0/1.48/((double)dec)); if (Npoint>16384) {Npoint=16384;} printf("Npoint = %i\n",Npoint); int powd, pad_len; if (power_two(Npoint,&powd)){powd++;} pad_len=int_pow(2,powd); init_table(pad_len); float fech=125000000.0/((float)dec); //gnuplot variable gnuplot_ctrl * h; double *y= (double *)malloc(Npoint*sizeof(double)); int i; int Ymax=1.5; //gnuplot object h=gnuplot_init(); gnuplot_setstyle(h,"lines"); gnuplot_set_xlabel(h,"time (us)"); gnuplot_set_ylabel(h,"signal"); //gnuplot_cmd(h,"set yrange [0:%d]", 2*Ymax); gnuplot_cmd(h,"set xrange [0:%d]",Npoint-1); char name[30]; if (mode_RP==0) { int powd, pad_len; if (power_two(Npoint,&powd)){powd++;} pad_len=int_pow(2,powd); double *pad=NULL; pad=(double *)malloc(pad_len*sizeof(double)); double *env=NULL; env=(double *)malloc(pad_len*sizeof(double)); gnuplot_cmd(h,"set yrange [-0.01:1.5]"); gnuplot_cmd(h,"set xrange [0:%d]",Npoint-1); int16_t *buff=(int16_t *)malloc((Npoint+1)*sizeof(int16_t)); while(1) { if(receive_int16_TCP_client(&sock, buff, Npoint+1)==1){break;} for (i=1 ; i<Npoint+1 ; i++){y[i-1]=(double)(buff[i])/409.6;} //divide by 409.6 to have voltage value zero_padding(y, pad, Npoint, pad_len, 1); envelope(pad, env, pad_len, fech, fmin, fmax, 0); gnuplot_resetplot(h); //gnuplot_plot_x(h, y, Npoint, "Oscillo int16_t"); gnuplot_plot_x(h, env, pad_len, "Oscillo int16_t"); //sprintf(name, "int%i.txt", l); //writefile(y, Npoint, name); l++; } free(buff); free(pad); free(env); } else if (mode_RP==1) { char *buff=(char *)malloc((Npoint+1)*sizeof(char)); while(1) { if(receive_TCP_client(&sock, buff, Npoint+1)==1){break;} for (i=1 ; i<Npoint+1 ; i++){y[i-1]=(double)(int_converter(buff[i]));} gnuplot_resetplot(h); gnuplot_plot_x(h, y, Npoint, "Oscillo 256 gray"); sprintf(name, "char%i.txt", l); //writefile(y, Npoint, name); l++; } free(buff); } else {printf("Problem of settings\n");} usleep(30); close(sock); free(y); return 0; }
void plotData(const parameters * p, fit_results * fr, plot_data * pd) { int i; char * str=(char*)calloc(256,sizeof(char)); plotOpen=1; handle=gnuplot_init(); printf("\nDATA PLOTS\n----------\n"); if(strcmp(p->plotMode,"1d")==0) { for(i=0;i<p->numVar;i++) { gnuplot_setstyle(handle,"points"); //set style for grid points if(strcmp(p->dataType,"chisq")==0) gnuplot_cmd(handle,"set ylabel 'Chisq'"); else gnuplot_cmd(handle,"set ylabel 'Value'"); sprintf(str,"set xlabel 'Parameter %i'",i+1); gnuplot_cmd(handle,str); gnuplot_plot_xy(handle, pd->data[i][i], pd->data[i][p->numVar], pd->plotDataSize[i], "Data"); if(pd->axisLabelStyle[i][i]==1) gnuplot_cmd(handle,"set format x '%%12.2E'"); if(pd->axisLabelStyle[i][p->numVar]==1) gnuplot_cmd(handle,"set format y '%%12.2E'"); gnuplot_setstyle(handle,"lines");//set style for fit data if(p->numVar==1) { gnuplot_plot_xy(handle, pd->fit[i][i], pd->fit[i][p->numVar], pd->numFitPlotPts, "Fit"); } else { if(i==0) gnuplot_plot_xy(handle, pd->fit[i][i], pd->fit[i][p->numVar], pd->numFitPtsPerVar, "Fit"); else if(i==1) gnuplot_plot_xygrid(handle, pd->fit[i][i], pd->fit[i][p->numVar], pd->numFitPtsPerVar*pd->numFitPtsPerVar, pd->numFitPtsPerVar, pd->numFitPtsPerVar, 0, "Fit"); else if(i==2) gnuplot_plot_xygrid(handle, pd->fit[i][i], pd->fit[i][p->numVar], pd->numFitPlotPts, pd->numFitPtsPerVar, pd->numFitPtsPerVar*pd->numFitPtsPerVar, 0, "Fit"); } //strcpy(str,fr->fitForm[i]);//retrieve fit data functional form //gnuplot_plot_equation(handle, str, "Fit (function)"); //plot confidence intervals if(p->plotCI==1) { gnuplot_plot_xy(handle,fr->ciXVal[i],fr->ciUVal[i],CI_DIM,"Upper 1-sigma confidence band"); gnuplot_plot_xy(handle,fr->ciXVal[i],fr->ciLVal[i],CI_DIM,"Lower 1-sigma confidence band"); /*strcpy(str,fr->ciUForm[0]); gnuplot_plot_equation(handle, str, "Upper 95% confidence band"); strcpy(str,fr->ciLForm[0]); gnuplot_plot_equation(handle, str, "Lower 95% confidence band"); strcpy(str,fr->piUForm[0]); gnuplot_plot_equation(handle, str, "Upper 95% prediction band"); strcpy(str,fr->piLForm[0]); gnuplot_plot_equation(handle, str, "Lower 95% prediction band");*/ } printf("Showing plot for parameter %i.\n",i+1); if(p->numVar==3) { if(i==0) printf("Parameter %i fixed to %Lf\nParameter %i fixed to %Lf\n",2,pd->fixedParVal[1],3,pd->fixedParVal[2]); if(i==1) printf("Parameter %i fixed to %Lf\nParameter %i fixed to %Lf\n",1,pd->fixedParVal[0],3,pd->fixedParVal[2]); if(i==2) printf("Parameter %i fixed to %Lf\nParameter %i fixed to %Lf\n",1,pd->fixedParVal[0],2,pd->fixedParVal[1]); } else if(p->numVar==2) { if(i==0) printf("Parameter %i fixed to %Lf\n",2,pd->fixedParVal[1]); if(i==1) printf("Parameter %i fixed to %Lf\n",1,pd->fixedParVal[0]); } printf("%i data points available for plot.\n",pd->plotDataSize[i]); if(i<(p->numVar-1)) plotPrompt(1); else plotPrompt(0); gnuplot_resetplot(handle); } } else if(strcmp(p->plotMode,"2d")==0) { if(p->numVar==3) { for(i=0;i<p->numVar;i++) { gnuplot_setstyle(handle,"points"); //set style for grid points if(i==0) { gnuplot_plot_xyz(handle, pd->data[i][1], pd->data[i][2], pd->data[i][p->numVar], pd->plotDataSize[i], "Data"); if(pd->axisLabelStyle[i][1]==1) gnuplot_cmd(handle,"set format x '%%12.2E'"); if(pd->axisLabelStyle[i][2]==1) gnuplot_cmd(handle,"set format y '%%12.2E'"); if(pd->axisLabelStyle[i][p->numVar]==1) gnuplot_cmd(handle,"set format z '%%12.2E'"); sprintf(str,"set xlabel 'Parameter 2'; set ylabel 'Parameter 3'"); } else if(i==1) { gnuplot_plot_xyz(handle, pd->data[i][0], pd->data[i][2], pd->data[i][p->numVar], pd->plotDataSize[i], "Data"); if(pd->axisLabelStyle[i][0]==1) gnuplot_cmd(handle,"set format x '%%12.2E'"); if(pd->axisLabelStyle[i][2]==1) gnuplot_cmd(handle,"set format y '%%12.2E'"); if(pd->axisLabelStyle[i][p->numVar]==1) gnuplot_cmd(handle,"set format z '%%12.2E'"); sprintf(str,"set xlabel 'Parameter 1'; set ylabel 'Parameter 3'"); } else if(i==2) { gnuplot_plot_xyz(handle, pd->data[i][0], pd->data[i][1], pd->data[i][p->numVar], pd->plotDataSize[i], "Data"); if(pd->axisLabelStyle[i][0]==1) gnuplot_cmd(handle,"set format x '%%12.2E'"); if(pd->axisLabelStyle[i][1]==1) gnuplot_cmd(handle,"set format y '%%12.2E'"); if(pd->axisLabelStyle[i][p->numVar]==1) gnuplot_cmd(handle,"set format z '%%12.2E'"); sprintf(str,"set xlabel 'Parameter 1'; set ylabel 'Parameter 2'"); } if(strcmp(p->dataType,"chisq")==0) gnuplot_cmd(handle,"set zlabel 'Chisq'"); else gnuplot_cmd(handle,"set zlabel 'Value'"); gnuplot_cmd(handle,str); gnuplot_setstyle(handle,"lines"); gnuplot_cmd(handle,"set grid");//set style for fit data if(i==0) gnuplot_plot_xyzgrid(handle, pd->fit[i][1], pd->fit[i][2], pd->fit[i][p->numVar], pd->numFitPlotPts, pd->numFitPtsPerVar*pd->numFitPtsPerVar, pd->numFitPtsPerVar, 0, "Fit"); else if(i==1) gnuplot_plot_xyzgrid(handle, pd->fit[i][0], pd->fit[i][2], pd->fit[i][p->numVar], pd->numFitPlotPts, pd->numFitPtsPerVar, 0, pd->numFitPtsPerVar, "Fit"); else if(i==2) gnuplot_plot_xyzgrid(handle, pd->fit[i][0], pd->fit[i][1], pd->fit[i][p->numVar], pd->numFitPtsPerVar*pd->numFitPtsPerVar, pd->numFitPtsPerVar, 0, 0, "Fit"); //strcpy(str,fr->fitForm[i]);//retrieve fit data functional form //gnuplot_plot_equation(handle, str, "Fit (function)"); printf("Showing surface plot with parameter %i fixed to %Lf\n",i+1,pd->fixedParVal[i]); printf("%i data points available for plot.\n",pd->plotDataSize[i]); if(i<(p->numVar-1)) plotPrompt(1); else plotPrompt(0); gnuplot_resetplot(handle); } } else if(p->numVar==2) { gnuplot_setstyle(handle,"points"); //set style for grid points gnuplot_plot_xyz(handle, pd->data[0][0], pd->data[0][1], pd->data[0][p->numVar], pd->plotDataSize[0], "Data"); if(pd->axisLabelStyle[0][0]==1) gnuplot_cmd(handle,"set format x '%%12.2E'"); if(pd->axisLabelStyle[0][1]==1) gnuplot_cmd(handle,"set format y '%%12.2E'"); if(pd->axisLabelStyle[0][p->numVar]==1) gnuplot_cmd(handle,"set format z '%%12.2E'"); if(strcmp(p->dataType,"chisq")==0) gnuplot_cmd(handle,"set zlabel 'Chisq'"); else gnuplot_cmd(handle,"set zlabel 'Value'"); sprintf(str,"set xlabel 'Parameter 1'; set ylabel 'Parameter 2'"); gnuplot_cmd(handle,str); gnuplot_setstyle(handle,"lines"); gnuplot_cmd(handle,"set grid");//set style for fit data //gnuplot_cmd(handle,"set dgrid3d 30,30 qnorm 2");//set style for fit data gnuplot_plot_xyzgrid(handle, pd->fit[0][0], pd->fit[0][1], pd->fit[0][p->numVar], pd->numFitPlotPts, pd->numFitPtsPerVar, 0, 0, "Fit"); //strcpy(str,fr->fitForm[0]);//retrieve fit data functional form //gnuplot_plot_equation(handle, str, "Fit (function)"); printf("Showing surface plot.\n"); printf("%i data points available for plot.\n",pd->plotDataSize[0]); plotPrompt(0); gnuplot_resetplot(handle); } } else if(strcmp(p->plotMode,"3d")==0) { if(p->numVar==3) { gnuplot_setstyle(handle,"points"); //set style for grid points gnuplot_plot_xyza(handle, pd->data[0][0], pd->data[0][1], pd->data[0][2], pd->data[0][p->numVar], pd->plotDataSize[0], "Data"); if(pd->axisLabelStyle[0][0]==1) gnuplot_cmd(handle,"set format x '%%12.2E'"); if(pd->axisLabelStyle[0][1]==1) gnuplot_cmd(handle,"set format y '%%12.2E'"); if(pd->axisLabelStyle[0][2]==1) gnuplot_cmd(handle,"set format z '%%12.2E'"); sprintf(str,"set xlabel 'Parameter 1'; set ylabel 'Parameter 2'; set zlabel 'Parameter 3'"); gnuplot_cmd(handle,str); sprintf(str,"set cbrange [%f:%f]",pd->min_m,pd->max_m); //set the color bar range gnuplot_cmd(handle,str); if(strcmp(p->fitType,"par3")==0) { gnuplot_setcolor(handle,"black"); gnuplot_cmd(handle,"set pointsize 1.5"); double xVert=(double)fr->fitVert[0]; double yVert=(double)fr->fitVert[1]; double zVert=(double)fr->fitVert[2]; gnuplot_plot_xyz(handle, &xVert, &yVert, &zVert, 1, "Fit Vertex"); } printf("Showing heatmap plot.\n"); printf("%i data points available for plot.\n",pd->plotDataSize[0]); plotPrompt(0); gnuplot_resetplot(handle); } } else { printf("ERROR: The plot mode '%s' defined in the data file '%s' is not supported!\n",p->plotMode,p->filename); exit(-1); } }
int main(int argc, char **argv) { gnuplot_ctrl *gam; char kcode; int exit_flag = 1; gam = gnuplot_init(); gnuplot_setstyle(gam, "lines"); plot_bezier(gam); // gnuplot_plot_slope(gam, 2.0, 0.0, "y=2x"); while(1){ switch(getkey()){ case 'x': exit_flag = 0; break; case 'a': gnuplot_resetplot(gam); gnuplot_plot_equation(gam, "log(x)", "logarithm") ; break; case '=': gnuplot_resetplot(gam); bez_adj(gam, target, COARSE, PLUS); plot_bezier(gam); break; case '-': gnuplot_resetplot(gam); bez_adj(gam, target, COARSE, MINUS); plot_bezier(gam); break; case '+': gnuplot_resetplot(gam); bez_adj(gam, target, FINE, PLUS); plot_bezier(gam); break; case '_': gnuplot_resetplot(gam); bez_adj(gam, target, FINE, MINUS); plot_bezier(gam); break; case '1': target = YONE; printf("\nset YONE as adjust target: %f\n", yone); break; case '2': target = YTWO; printf("\nset YTWO as adjust target: %f\n", ytwo); break; case '3': target = XONE; printf("\nset XONE as adjust target: %f\n", xone); break; case '4': target = XTWO; printf("\nset XTWO as adjust target: %f\n", xtwo); break; default: break; } if (!exit_flag) break; usleep(500*1000); } print_curve(); gnuplot_close(gam); return 0; }
int main(int argc, char *argv[]) { gnuplot_ctrl * h1, * h2, * h3, * h4 ; double x[NPOINTS] ; double y[NPOINTS] ; int i ; /* * Initialize the gnuplot handle */ printf("*** example of gnuplot control through C ***\n") ; h1 = gnuplot_init() ; /* * Slopes */ gnuplot_setstyle(h1, "lines") ; printf("*** plotting slopes\n") ; printf("y = x\n") ; gnuplot_plot_slope(h1, 1.0, 0.0, "unity slope") ; sleep(SLEEP_LGTH) ; printf("y = 2*x\n") ; gnuplot_plot_slope(h1, 2.0, 0.0, "y=2x") ; sleep(SLEEP_LGTH) ; printf("y = -x\n") ; gnuplot_plot_slope(h1, -1.0, 0.0, "y=-x") ; sleep(SLEEP_LGTH) ; /* * Equations */ gnuplot_resetplot(h1) ; printf("\n\n") ; printf("*** various equations\n") ; printf("y = sin(x)\n") ; gnuplot_plot_equation(h1, "sin(x)", "sine") ; sleep(SLEEP_LGTH) ; printf("y = log(x)\n") ; gnuplot_plot_equation(h1, "log(x)", "logarithm") ; sleep(SLEEP_LGTH) ; printf("y = sin(x)*cos(2*x)\n") ; gnuplot_plot_equation(h1, "sin(x)*cos(2*x)", "sine product") ; sleep(SLEEP_LGTH) ; /* * Styles */ gnuplot_resetplot(h1) ; printf("\n\n") ; printf("*** showing styles\n") ; printf("sine in points\n") ; gnuplot_setstyle(h1, "points") ; gnuplot_plot_equation(h1, "sin(x)", "sine") ; sleep(SLEEP_LGTH) ; printf("sine in impulses\n") ; gnuplot_setstyle(h1, "impulses") ; gnuplot_plot_equation(h1, "sin(x)", "sine") ; sleep(SLEEP_LGTH) ; printf("sine in steps\n") ; gnuplot_setstyle(h1, "steps") ; gnuplot_plot_equation(h1, "sin(x)", "sine") ; sleep(SLEEP_LGTH) ; /* * User defined 1d and 2d point sets */ gnuplot_resetplot(h1) ; gnuplot_setstyle(h1, "impulses") ; printf("\n\n") ; printf("*** user-defined lists of doubles\n") ; for (i=0 ; i<NPOINTS ; i++) { x[i] = (double)i*i ; } gnuplot_plot_x(h1, x, NPOINTS, "user-defined doubles") ; sleep(SLEEP_LGTH) ; printf("*** user-defined lists of points\n"); for (i=0 ; i<NPOINTS ; i++) { x[i] = (double)i ; y[i] = (double)i * (double)i ; } gnuplot_resetplot(h1) ; gnuplot_setstyle(h1, "points") ; gnuplot_plot_xy(h1, x, y, NPOINTS, "user-defined points") ; sleep(SLEEP_LGTH) ; /* * Multiple output screens */ printf("\n\n") ; printf("*** multiple output windows\n") ; gnuplot_resetplot(h1) ; gnuplot_setstyle(h1, "lines") ; h2 = gnuplot_init() ; gnuplot_setstyle(h2, "lines") ; h3 = gnuplot_init() ; gnuplot_setstyle(h3, "lines") ; h4 = gnuplot_init() ; gnuplot_setstyle(h4, "lines") ; printf("window 1: sin(x)\n") ; gnuplot_plot_equation(h1, "sin(x)", "sin(x)") ; sleep(SLEEP_LGTH) ; printf("window 2: x*sin(x)\n") ; gnuplot_plot_equation(h2, "x*sin(x)", "x*sin(x)") ; sleep(SLEEP_LGTH) ; printf("window 3: log(x)/x\n") ; gnuplot_plot_equation(h3, "log(x)/x", "log(x)/x"); sleep(SLEEP_LGTH) ; printf("window 4: sin(x)/x\n") ; gnuplot_plot_equation(h4, "sin(x)/x", "sin(x)/x") ; sleep(SLEEP_LGTH) ; /* * close gnuplot handles */ printf("\n\n") ; printf("*** end of gnuplot example\n") ; gnuplot_close(h1) ; gnuplot_close(h2) ; gnuplot_close(h3) ; gnuplot_close(h4) ; return 0 ; }
void TwoStream_Initializer::check_step(ParticleList* particles, HOMoments** moments,HOMoments* moments_old,FieldData** fields,ParallelInfo* myinfo) { if(myinfo->myid_mpi == 0) { particles->plot_particles(pdata); double pEnergy = ((fields[0] -> evaluate_energy())); double kEnergy = moments[0] -> evaluate_energy(); Energy_array[nplot] = pEnergy; kEnergy_array[nplot] = kEnergy; TEnergy_array[nplot] = (E0+kE0 - (kEnergy + pEnergy))/(E0+kE0); //printf("Energy Error= %e\n",(E0+kE0 - (Energy_array[nplot]+kEnergy_array[nplot]))/(E0+kE0)); max_t_array[nplot] = (nplot-1)*pdata->dt*2; if(nplot == 1) { max_array[0] = log(Energy_array[0]); max_t_array[nmax_array] = pdata->dt; nmax_array++; } else if(nplot > 1) { if(Energy_array[nplot-1] > fmax(Energy_array[nplot-2],Energy_array[nplot])) { //max_array[nmax_array] = log(Energy_array[nplot-1]); //max_t_array[nmax_array] = (nplot-1); //realkind period = (max_t_array[nmax_array]-max_t_array[nmax_array-1])*pdata->dt; //realkind vphase = 2.0*pi_const/period* 1.0*pdata->Lx/(2.0*pi_const); //printf("Energy fluctuation period = %f\n",period); //printf("Phase velocity = %f\n",vphase); //printf("Energy decay rate = %f\n",(max_array[nmax_array]-max_array[nmax_array-1])/ // (pdata->dt*(max_t_array[nmax_array]-max_t_array[nmax_array-1]))); nmax_array++; } } realkind charge_cons = moments[0] -> check_charge(moments_old); printf("Charge conservation = %e\n",charge_cons); charge_cons_array[nplot] = charge_cons; if((nplot > 0)&&(nplot%10 == 9)) { if(pdata->plot_flag){ gnuplot_resetplot(plot); gnuplot_resetplot(kenergy_plot); gnuplot_resetplot(Tenergy_plot); gnuplot_resetplot(charge_cons_plot); } } nplot++; if((pdata->plot_flag)&&(nplot%10 == 9)) { gnuplot_plot_xy(plot,max_t_array+1,Energy_array+1,nplot-1,"Field Energy"); gnuplot_cmd(plot,"replot \"E_vec.csv\" title \"Matlab Code\" with points"); gnuplot_plot_x(kenergy_plot,kEnergy_array,nplot,"Particle Energy"); gnuplot_plot_x(Tenergy_plot,TEnergy_array,nplot,"Total Energy"); gnuplot_plot_x(charge_cons_plot,charge_cons_array,nplot,"Charge Conservation"); } } }
void EnergyCons_Initializer::check_step(ParticleList* particles, HOMoments** moments,HOMoments* moments_old,FieldData** fields,ParallelInfo* myinfo) { // Print out the sum of the x-component of the current if(myinfo->myid_mpi == 0) { Energy_array[nplot] = ((fields[0] -> evaluate_energy())); kEnergy_array[nplot] = particles->evaluate_energy(pdata); TEnergy_array[nplot] = kEnergy_array[nplot] + Energy_array[nplot]; printf("Energy Error= %e\n",(E0+kE0 - (Energy_array[nplot]+kEnergy_array[nplot]))/(E0+kE0)); if(nplot == 1) { max_array[0] = log(Energy_array[0]); max_t_array[nmax_array] = pdata->dt; nmax_array++; } else if(nplot > 1) { if(Energy_array[nplot-1] > fmax(Energy_array[nplot-2],Energy_array[nplot])) { max_array[nmax_array] = log(Energy_array[nplot-1]); max_t_array[nmax_array] = (nplot-1); float period = (max_t_array[nmax_array]-max_t_array[nmax_array-1])*pdata->dt; float vphase = 2.0*pi_const/period* 1.0*pdata->Lx/(2.0*pi_const); printf("Energy fluctuation period = %f\n",period); printf("Phase velocity = %f\n",vphase); printf("Energy decay rate = %f\n",(max_array[nmax_array]-max_array[nmax_array-1])/ (pdata->dt*(max_t_array[nmax_array]-max_t_array[nmax_array-1]))); nmax_array++; } } if(nplot > 0) { gnuplot_resetplot(plot); gnuplot_resetplot(kenergy_plot); gnuplot_resetplot(Tenergy_plot); } nplot++; gnuplot_plot_x(plot,Energy_array,nplot,"Field Energy"); gnuplot_plot_x(kenergy_plot,kEnergy_array,nplot,"Particle Energy"); gnuplot_plot_x(Tenergy_plot,TEnergy_array,nplot,"Total Energy"); //gnuplot_setstyle(plot,"lines"); gnuplot_plot_xy(plot,max_t_array,max_array,nmax_array,NULL); //gnuplot_setstyle(plot,"points"); } }