void PlPlotWidget::plotLinearFit(int size, std::vector<double> &xp,std::vector<double> &yp,std::vector<double> &yp_err, double m, double c){ plot->clearWidget(); //plot->setBackgroundColor(255,255,255,1); int i; double max_x, max_y; std::vector<double>::iterator result_min_x, result_max_x; std::vector<double>::iterator result_min_y, result_max_y; PLFLT *x = new PLFLT[size]; PLFLT *y = new PLFLT[size]; PLFLT *y_fit = new PLFLT[size]; PLFLT *y_err_hi = new PLFLT[size]; PLFLT *y_err_lo = new PLFLT[size]; for(i=0;i<size;i++){ // is there a better way with first value x[i]=xp[i]; y[i]=yp[i]; y_fit[i]=m*xp[i]+c; y_err_hi[i]=yp[i]+yp_err[i]; y_err_lo[i]=yp[i]-yp_err[i]; } result_min_x = std::min_element(xp.begin(), xp.end()); result_max_x = std::max_element(xp.begin(), xp.end()); result_min_y = std::min_element(yp.begin(), yp.end()); result_max_y = std::max_element(yp.begin(), yp.end()); max_x = (*result_max_x)*(1.2); //sets the axis to be 20% larger than the max value max_y = (*result_max_y)*(1.2); plcol0( 14 ); plenv( 0, max_x, 0, max_y, 0, 1 ); plcol0( 1 ); pllab( "time (s)", "\gl", "FRAP DATA" ); plcol0( 14 ); plwid( 2 ); plpoin( size, x, y, 20); plerry( size, x, y_err_hi,y_err_lo); plwid( 1 ); plcol0( 14 ); plwid( 2 ); plline( size, x, y_fit ); plwid( 1 ); delete[] x; delete[] y; delete[] y_fit; delete[] y_err_hi; delete[] y_err_lo; }
MZ_DLLEXPORT void c_plshades( PLFLT **a, PLINT nx, PLINT ny, PLINT (*defined) (PLFLT, PLFLT), PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax, PLFLT *clevel, PLINT nlevel, PLINT fill_width, PLINT cont_color, PLINT cont_width, void (*fill) (PLINT, PLFLT *, PLFLT *), PLINT rectangular, void (*pltr) (PLFLT, PLFLT, PLFLT *, PLFLT *, PLPointer), PLPointer pltr_data ) { PLFLT shade_min, shade_max, shade_color; PLINT i, init_color, init_width; for (i = 0; i < nlevel-1; i++) { shade_min = clevel[i]; shade_max = clevel[i+1]; shade_color = i / (PLFLT) (nlevel-2); /* The constants in order mean * (1) color map1, * (0, 0, 0, 0) all edge effects will be done with plcont rather * than the normal plshade drawing which gets partially blocked * when sequential shading is done as in the present case */ plshade(a, nx, ny, defined, xmin, xmax, ymin, ymax, shade_min, shade_max, 1, shade_color, fill_width, 0, 0, 0, 0, fill, rectangular, pltr, pltr_data); } if(cont_color > 0 && cont_width > 0) { init_color = plsc->icol0; init_width = plsc->width; plcol0(cont_color); plwid(cont_width); plcont(a, nx, ny, 1, nx, 1, ny, clevel, nlevel, pltr, pltr_data); plcol0(init_color); plwid(init_width); } }
static void draw_boundary(PLINT slope, PLFLT *x, PLFLT *y) { int i; if (pen_col_min != 0 && pen_wd_min != 0 && min_points != 0) { plcol0(pen_col_min); plwid(pen_wd_min); if (min_points == 4 && slope == 0) { /* swap points 1 and 3 */ i = min_pts[1]; min_pts[1] = min_pts[3]; min_pts[3] = i; } pljoin(x[min_pts[0]], y[min_pts[0]], x[min_pts[1]], y[min_pts[1]]); if (min_points == 4) { pljoin(x[min_pts[2]], y[min_pts[2]], x[min_pts[3]], y[min_pts[3]]); } } if (pen_col_max != 0 && pen_wd_max != 0 && max_points != 0) { plcol0(pen_col_max); plwid(pen_wd_max); if (max_points == 4 && slope == 0) { /* swap points 1 and 3 */ i = max_pts[1]; max_pts[1] = max_pts[3]; max_pts[3] = i; } pljoin(x[max_pts[0]], y[max_pts[0]], x[max_pts[1]], y[max_pts[1]]); if (max_points == 4) { pljoin(x[max_pts[2]], y[max_pts[2]], x[max_pts[3]], y[max_pts[3]]); } } }
static void plshade_int(PLFLT (*f2eval) (PLINT, PLINT, PLPointer), PLPointer f2eval_data, PLFLT (*c2eval) (PLINT, PLINT, PLPointer), PLPointer c2eval_data, PLINT (*defined) (PLFLT, PLFLT), PLFLT missing_min, PLFLT missing_max, PLINT nx, PLINT ny, PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax, PLFLT shade_min, PLFLT shade_max, PLINT sh_cmap, PLFLT sh_color, PLINT sh_width, PLINT min_color, PLINT min_width, PLINT max_color, PLINT max_width, void (*fill) (PLINT, PLFLT *, PLFLT *), PLINT rectangular, void (*pltr) (PLFLT, PLFLT, PLFLT *, PLFLT *, PLPointer), PLPointer pltr_data) { PLINT init_width, n, slope = 0, ix, iy; int count, i, j, nxny; PLFLT *a, *a0, *a1, dx, dy; PLFLT x[8], y[8], xp[2], tx, ty; int *c, *c0, *c1; if (plsc->level < 3) { plabort("plfshade: window must be set up first"); return; } if (nx <= 0 || ny <= 0) { plabort("plfshade: nx and ny must be positive"); return; } if (shade_min >= shade_max) { plabort("plfshade: shade_max must exceed shade_min"); return; } if (pltr == NULL || pltr_data == NULL) rectangular = 1; int_val = shade_max - shade_min; init_width = plsc->width; pen_col_min = min_color; pen_col_max = max_color; pen_wd_min = min_width; pen_wd_max = max_width; plstyl((PLINT) 0, NULL, NULL); plwid(sh_width); if (fill != NULL) { switch (sh_cmap) { case 0: plcol0((PLINT) sh_color); break; case 1: plcol1(sh_color); break; default: plabort("plfshade: invalid color map selection"); return; } } /* alloc space for value array, and initialize */ /* This is only a temporary kludge */ nxny = nx * ny; if ((a = (PLFLT *) malloc(nxny * sizeof(PLFLT))) == NULL) { plabort("plfshade: unable to allocate memory for value array"); return; } for (ix = 0; ix < nx; ix++) for (iy = 0; iy < ny; iy++) a[iy + ix*ny] = f2eval(ix, iy, f2eval_data); /* alloc space for condition codes */ if ((c = (int *) malloc(nxny * sizeof(int))) == NULL) { plabort("plfshade: unable to allocate memory for condition codes"); free(a); return; } sh_min = shade_min; sh_max = shade_max; set_cond(c, a, nxny); dx = (xmax - xmin) / (nx - 1); dy = (ymax - ymin) / (ny - 1); a0 = a; a1 = a + ny; c0 = c; c1 = c + ny; for (ix = 0; ix < nx - 1; ix++) { for (iy = 0; iy < ny - 1; iy++) { count = c0[iy] + c0[iy + 1] + c1[iy] + c1[iy + 1]; /* No filling needs to be done for these cases */ if (count >= UNDEF) continue; if (count == 4 * POS) continue; if (count == 4 * NEG) continue; /* Entire rectangle can be filled */ if (count == 4 * OK) { /* find biggest rectangle that fits */ if (rectangular) { big_recl(c0 + iy, ny, nx - ix, ny - iy, &i, &j); } else { i = j = 1; } x[0] = x[1] = ix; x[2] = x[3] = ix+i; y[0] = y[3] = iy; y[1] = y[2] = iy+j; if (pltr && pltr_data) { for (i = 0; i < 4; i++) { (*pltr) (x[i], y[i], &tx, &ty, pltr_data); x[i] = tx; y[i] = ty; } } else { for (i = 0; i < 4; i++) { x[i] = xmin + x[i]*dx; y[i] = ymin + y[i]*dy; } } if (fill != NULL) exfill (fill, defined, (PLINT) 4, x, y); iy += j - 1; continue; } /* Only part of rectangle can be filled */ n_point = min_points = max_points = 0; n = find_interval(a0[iy], a0[iy + 1], c0[iy], c0[iy + 1], xp); for (j = 0; j < n; j++) { x[j] = ix; y[j] = iy + xp[j]; } i = find_interval(a0[iy + 1], a1[iy + 1], c0[iy + 1], c1[iy + 1], xp); for (j = 0; j < i; j++) { x[j + n] = ix + xp[j]; y[j + n] = iy + 1; } n += i; i = find_interval(a1[iy + 1], a1[iy], c1[iy + 1], c1[iy], xp); for (j = 0; j < i; j++) { x[n + j] = ix + 1; y[n + j] = iy + 1 - xp[j]; } n += i; i = find_interval(a1[iy], a0[iy], c1[iy], c0[iy], xp); for (j = 0; j < i; j++) { x[n + j] = ix + 1 - xp[j]; y[n + j] = iy; } n += i; if (pltr && pltr_data) { for (i = 0; i < n; i++) { (*pltr) (x[i], y[i], &tx, &ty, pltr_data); x[i] = tx; y[i] = ty; } } else { for (i = 0; i < n; i++) { x[i] = xmin + x[i]*dx; y[i] = ymin + y[i]*dy; } } if (min_points == 4) slope = plctestez(a, nx, ny, ix, iy, shade_min); if (max_points == 4) slope = plctestez(a, nx, ny, ix, iy, shade_max); /* n = number of end of line segments */ /* min_points = number times shade_min meets edge */ /* max_points = number times shade_max meets edge */ /* special cases: check number of times a contour is in a box */ switch ((min_points << 3) + max_points) { case 000: case 020: case 002: case 022: if (fill != NULL && n > 0) exfill (fill, defined, n, x, y); break; case 040: /* 2 contour lines in box */ case 004: if (n != 6) fprintf(stderr, "plfshade err n=%d !6", (int) n); if (slope == 1 && c0[iy] == OK) { if (fill != NULL) exfill (fill, defined, n, x, y); } else if (slope == 1) { poly(fill, defined, x, y, 0, 1, 2, -1); poly(fill, defined, x, y, 3, 4, 5, -1); } else if (c0[iy + 1] == OK) { if (fill != NULL) exfill (fill, defined, n, x, y); } else { poly(fill, defined, x, y, 0, 1, 5, -1); poly(fill, defined, x, y, 2, 3, 4, -1); } break; case 044: if (n != 8) fprintf(stderr, "plfshade err n=%d !8", (int) n); if (slope == 1) { poly(fill, defined, x, y, 0, 1, 2, 3); poly(fill, defined, x, y, 4, 5, 6, 7); } else { poly(fill, defined, x, y, 0, 1, 6, 7); poly(fill, defined, x, y, 2, 3, 4, 5); } break; case 024: case 042: /* 3 contours */ if (n != 7) fprintf(stderr, "plfshade err n=%d !7", (int) n); if ((c0[iy] == OK || c1[iy+1] == OK) && slope == 1) { if (fill != NULL) exfill (fill, defined, n, x, y); } else if ((c0[iy+1] == OK || c1[iy] == OK) && slope == 0) { if (fill !=NULL) exfill (fill, defined, n, x, y); } else if (c0[iy] == OK) { poly(fill, defined, x, y, 0, 1, 6, -1); poly(fill, defined, x, y, 2, 3, 4, 5); } else if (c0[iy+1] == OK) { poly(fill, defined, x, y, 0, 1, 2, -1); poly(fill, defined, x, y, 3, 4, 5, 6); } else if (c1[iy+1] == OK) { poly(fill, defined, x, y, 0, 1, 5, 6); poly(fill, defined, x, y, 2, 3, 4, -1); } else if (c1[iy] == OK) { poly(fill, defined, x, y, 0, 1, 2, 3); poly(fill, defined, x, y, 4, 5, 6, -1); } else { fprintf(stderr, "plfshade err logic case 024:042\n"); } break; default: fprintf(stderr, "prog err switch\n"); break; } draw_boundary(slope, x, y); if (fill != NULL) { plwid(sh_width); if (sh_cmap == 0) plcol0((PLINT) sh_color); else if (sh_cmap == 1) plcol1(sh_color); } } a0 = a1; c0 = c1; a1 += ny; c1 += ny; } free(c); free(a); plwid(init_width); }
int plp_draw(double *signal, int *signal_lengths, int ylog_scale) { int count; int i,j; int col; int dowind; for (i=0;i<2*NOF_INPUT_ITF;i++) { if (signal_lengths[i] > INPUT_MAX_SAMPLES) { moderror_msg("plplot buffer configured for %d samples but received %d in signal %d\n", INPUT_MAX_SAMPLES,signal_lengths[i],i); return -1; } } dowind=0; xmax=-1; for(i=0;i<2*NOF_INPUT_ITF;i++) { if (signal_lengths[i]) { dowind=1; xmax = (PLFLT) MAX(xmax,signal_lengths[i]); for (j=0;j<signal_lengths[i];j++) { ymin = (PLFLT) MIN(ymin,signal[i*INPUT_MAX_SAMPLES+j]); ymax = (PLFLT) MAX(ymax,signal[i*INPUT_MAX_SAMPLES+j]); } } } if (!dowind) { xmin=0; xmax=100; ymin=-1; ymax=1; } plclear(); plscolbg(255, 255, 255); plvsta(); plwid(1); plwind(xmin, xmax, ymin*1.1, ymax*1.1); plcol0(1); if (ylog_scale) { plbox(logaxis_x, 0., 0, logaxis_y, 0., 0); } else { plbox(axis_x, 0., 0, axis_y, 0., 0); } plcol0(4); plbox("g", 0, 0, "g", 0, 0); plcol0(1); pllab(xlabel, ylabel, ""); draw_legend(); plwid(4); col=3; for (i=0;i<2*NOF_INPUT_ITF;i++) { if (signal_lengths[i]) { plcol0(line_colors[i]); plline(signal_lengths[i], t, &signal[i*INPUT_MAX_SAMPLES]); col++; if (col==4) col++; } } plflush(); // force an update of the tk driver }