void c_plpoin(PLINT n, PLFLT *x, PLFLT *y, PLINT code) { PLINT i, sym, ifont = plsc->cfont; if (plsc->level < 3) { plabort("plpoin: Please set up window first"); return; } if (code < -1 || code > 127) { plabort("plpoin: Invalid code"); return; } if (code == -1) { for (i = 0; i < n; i++) pljoin(x[i], y[i], x[i], y[i]); } else { if (ifont > numberfonts) ifont = 1; sym = *(fntlkup + (ifont - 1) * numberchars + code); for (i = 0; i < n; i++) plhrsh(sym, plP_wcpcx(x[i]), plP_wcpcy(y[i])); } }
static void plstrip_legend(PLStrip *mystripc, int first) { int i; PLFLT sc, dy; /* draw legend */ plgchr(&sc, &dy); sc = dy = dy/100; plwind(-0.01, 1.01, -0.01, 1.01); for (i=0; i<PEN; i++) { if (mystripc->npts[i] || first) { plcol(mystripc->colline[i]); pllsty(mystripc->styline[i]); pljoin(mystripc->xlpos, mystripc->ylpos - sc, mystripc->xlpos + 0.1, mystripc->ylpos - sc); plcol(mystripc->collab); plptex(mystripc->xlpos + 0.11, mystripc->ylpos - sc, 0., 0., 0, mystripc->legline[i]); sc += dy; } } plwind(mystripc->xmin, mystripc->xmax, mystripc->ymin, mystripc->ymax); plflush(); }
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 ); plwidth( 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 ); plwidth( 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]] ); } } }
int main(int argc, char *argv[]) { int i, j; PLFLT dtr, theta, dx, dy, r; char text[4]; static PLFLT x0[361], y0[361]; static PLFLT x[361], y[361]; dtr = PI / 180.0; for (i = 0; i <= 360; i++) { x0[i] = cos(dtr * i); y0[i] = sin(dtr * i); } /* Parse and process command line arguments */ (void) plparseopts(&argc, argv, PL_PARSE_FULL); /* Initialize plplot */ plinit(); /* Set up viewport and window, but do not draw box */ plenv(-1.3, 1.3, -1.3, 1.3, 1, -2); for (i = 1; i <= 10; i++) { for (j = 0; j <= 360; j++) { x[j] = 0.1 * i * x0[j]; y[j] = 0.1 * i * y0[j]; } /* Draw circles for polar grid */ plline(361, x, y); } plcol0(2); for (i = 0; i <= 11; i++) { theta = 30.0 * i; dx = cos(dtr * theta); dy = sin(dtr * theta); /* Draw radial spokes for polar grid */ pljoin(0.0, 0.0, dx, dy); sprintf(text, "%d", ROUND(theta)); /* Write labels for angle */ /* Slightly off zero to avoid floating point logic flips at 90 and 270 deg. */ if (dx >= -0.00001) plptex(dx, dy, dx, dy, -0.15, text); else plptex(dx, dy, -dx, -dy, 1.15, text); } /* Draw the graph */ for (i = 0; i <= 360; i++) { r = sin(dtr * (5 * i)); x[i] = x0[i] * r; y[i] = y0[i] * r; } plcol0(3); plline(361, x, y); plcol0(4); plmtex("t", 2.0, 0.5, 0.5, "#frPLplot Example 3 - r(#gh)=sin 5#gh"); /* Close the plot at end */ plend(); exit(0); }
void c_plbin(PLINT nbin, PLFLT *x, PLFLT *y, PLINT flags) { PLINT i; PLFLT xmin, xmax, vpwxmi, vpwxma, vpwymi, vpwyma; if (plsc->level < 3) { plabort("plbin: Please set up window first"); return; } /* Check x[i] are in ascending order */ for (i = 0; i < nbin - 1; i++) { if (x[i] >= x[i + 1]) { plabort("plbin: Elements of x array must be increasing"); return; } } plgvpw(&vpwxmi, &vpwxma, &vpwymi, &vpwyma); if (!(flags & 1)) { for (i = 0; i < nbin - 1; i++) { if (!(flags & 4) || (y[i] != vpwymi)) { pljoin(x[i], vpwymi, x[i], y[i]); pljoin(x[i], y[i], x[i + 1], y[i]); pljoin(x[i + 1], y[i], x[i + 1], vpwymi); } } if (flags & 2) { if (!(flags & 4) || (y[i] != vpwymi)) { int xm = x[i] + (x[i] - x[i-1]); pljoin(x[i], vpwymi, x[i], y[i]); pljoin(x[i], y[i], xm, y[i]); pljoin(xm, y[i], xm, vpwymi); } } else { if (x[i] < vpwxma) { if (!(flags & 4) || (y[i] != vpwymi)) { pljoin(x[i], vpwymi, x[i], y[i]); pljoin(x[i], y[i], vpwxma, y[i]); pljoin(vpwxma, y[i], vpwxma, vpwymi); } } } } else { if (nbin < 2) return; if (flags & 2) { xmin = MAX(vpwxmi, 0.5 * (3 * x[0] - x[1])); } else { xmin = vpwxmi; } /* Vince fixed bug May 1998 */ xmax = MAX(0.5 * (x[0] + x[1]), vpwxmi); if (xmin < xmax) { pljoin(xmin, vpwymi, xmin, y[0]); pljoin(xmin, y[0], xmax, y[0]); pljoin(xmax, y[0], xmax, vpwymi); } for (i = 1; i < nbin - 1; i++) { xmin = xmax; xmax = MIN(0.5 * (x[i] + x[i + 1]), vpwxma); if (!(flags & 4) || (y[i] != vpwymi)) { pljoin(xmin, vpwymi, xmin, y[i]); pljoin(xmin, y[i], xmax, y[i]); pljoin(xmax, y[i], xmax, vpwymi); } } xmin = xmax; xmax = vpwxma; if (flags & 2) { xmax = MIN(vpwxma, 0.5 * (3 * x[i] - x[i-1])); } else { xmax = vpwxma; } if (xmin < xmax) { if (!(flags & 4) || (y[i] != vpwymi)) { pljoin(xmin, vpwymi, xmin, y[i]); pljoin(xmin, y[i], xmax, y[i]); pljoin(xmax, y[i], xmax, vpwymi); } } } }
int main( int argc, const char *argv[] ) { int i; PLFLT dtr, theta, dx, dy, r, offset; char text[4]; static PLFLT x0[361], y0[361]; static PLFLT x[361], y[361]; dtr = M_PI / 180.0; for ( i = 0; i <= 360; i++ ) { x0[i] = cos( dtr * i ); y0[i] = sin( dtr * i ); } // Parse and process command line arguments (void) plparseopts( &argc, argv, PL_PARSE_FULL ); // Set orientation to portrait - note not all device drivers // support this, in particular most interactive drivers do not plsori( 1 ); // Initialize plplot plinit(); // Set up viewport and window, but do not draw box plenv( -1.3, 1.3, -1.3, 1.3, 1, -2 ); // Draw circles for polar grid for ( i = 1; i <= 10; i++ ) { plarc( 0.0, 0.0, 0.1 * i, 0.1 * i, 0.0, 360.0, 0.0, 0 ); } plcol0( 2 ); for ( i = 0; i <= 11; i++ ) { theta = 30.0 * i; dx = cos( dtr * theta ); dy = sin( dtr * theta ); // Draw radial spokes for polar grid pljoin( 0.0, 0.0, dx, dy ); sprintf( text, "%d", ROUND( theta ) ); // Write labels for angle if ( theta < 9.99 ) { offset = 0.45; } else if ( theta < 99.9 ) { offset = 0.30; } else { offset = 0.15; } // Slightly off zero to avoid floating point logic flips at 90 and 270 deg. if ( dx >= -0.00001 ) plptex( dx, dy, dx, dy, -offset, text ); else plptex( dx, dy, -dx, -dy, 1. + offset, text ); } // Draw the graph for ( i = 0; i <= 360; i++ ) { r = sin( dtr * ( 5 * i ) ); x[i] = x0[i] * r; y[i] = y0[i] * r; } plcol0( 3 ); plline( 361, x, y ); plcol0( 4 ); plmtex( "t", 2.0, 0.5, 0.5, "#frPLplot Example 3 - r(#gh)=sin 5#gh" ); // Close the plot at end plend(); exit( 0 ); }
static void grid_box(const char *xopt, PLFLT xtick1, PLINT nxsub1, const char *yopt, PLFLT ytick1, PLINT nysub1) { PLINT lgx, lhx, llx; PLINT lgy, lhy, lly; PLFLT vpwxmi, vpwxma, vpwymi, vpwyma; PLFLT vpwxmin, vpwxmax, vpwymin, vpwymax; PLFLT tn, temp, tcrit, tspace = 0.1; PLINT i; /* Set plot options from input */ lgx = plP_stsearch(xopt, 'g'); lhx = plP_stsearch(xopt, 'h'); llx = plP_stsearch(xopt, 'l'); lgy = plP_stsearch(yopt, 'g'); lhy = plP_stsearch(yopt, 'h'); lly = plP_stsearch(yopt, 'l'); plgvpw(&vpwxmin, &vpwxmax, &vpwymin, &vpwymax); /* n.b. large change; vpwxmi always numerically less than vpwxma, and * similarly for vpwymi */ vpwxmi = (vpwxmax > vpwxmin) ? vpwxmin : vpwxmax; vpwxma = (vpwxmax > vpwxmin) ? vpwxmax : vpwxmin; vpwymi = (vpwymax > vpwymin) ? vpwymin : vpwymax; vpwyma = (vpwymax > vpwymin) ? vpwymax : vpwymin; /* Draw grid in x direction. */ if (lgx) { for (tn = xtick1 * floor(vpwxmi/xtick1); tn <= vpwxma; tn += xtick1) { if (lhx) { if (llx) { PLFLT otemp = tn; for (i = 0; i <= 7; i++) { temp = tn + xlog[i]; tcrit = (temp - otemp)*tspace; otemp = temp; if (BETW(temp, vpwxmi+tcrit, vpwxma-tcrit)) pljoin(temp, vpwymi, temp, vpwyma); } } else { for (i = 1; i <= nxsub1 - 1; i++) { temp = tn + i * xtick1 / nxsub1; tcrit = xtick1 / nxsub1 * tspace; if (BETW(temp, vpwxmi+tcrit, vpwxma-tcrit)) pljoin(temp, vpwymi, temp, vpwyma); } } } tcrit = xtick1*tspace; if (BETW(tn, vpwxmi+tcrit, vpwxma-tcrit)) pljoin(tn, vpwymi, tn, vpwyma); } } /* Draw grid in y direction */ if (lgy) { tn = ytick1 * floor(vpwymi / ytick1 + tspace); for (tn = ytick1 * floor(vpwymi/ytick1); tn <= vpwyma; tn += ytick1) { if (lhy) { if (lly) { PLFLT otemp = tn; for (i = 0; i <= 7; i++) { temp = tn + xlog[i]; tcrit = (temp - otemp)*tspace; otemp = temp; if (BETW(temp, vpwymi+tcrit, vpwyma-tcrit)) pljoin(vpwxmi, temp, vpwxma, temp); } } else { for (i = 1; i <= nysub1 - 1; i++) { temp = tn + i * ytick1 / nysub1; tcrit = ytick1 / nysub1 * tspace; if (BETW(temp, vpwymi+tcrit, vpwyma-tcrit)) pljoin(vpwxmi, temp, vpwxma, temp); } } } tcrit = ytick1*tspace; if (BETW(tn, vpwymi+tcrit, vpwyma-tcrit)) pljoin(vpwxmi, tn, vpwxma, tn); } } }
void plot4(void) { int i, j; PLFLT dtr, theta, dx, dy, r; char text[3]; PLFLT x0[361], y0[361]; PLFLT x[361], y[361]; dtr = PI / 180.0; for (i = 0; i <= 360; i++) { x0[i] = cos(dtr * i); y0[i] = sin(dtr * i); } /* Set up viewport and window, but do not draw box */ plenv(-1.3, 1.3, -1.3, 1.3, 1, -2); for (i = 1; i <= 10; i++) { for (j = 0; j <= 360; j++) { x[j] = 0.1 * i * x0[j]; y[j] = 0.1 * i * y0[j]; } /* Draw circles for polar grid */ plline(361, x, y); } plcol0(2); for (i = 0; i <= 11; i++) { theta = 30.0 * i; dx = cos(dtr * theta); dy = sin(dtr * theta); /* Draw radial spokes for polar grid */ pljoin(0.0, 0.0, dx, dy); sprintf(text, "%d", ROUND(theta)); /* Write labels for angle */ /* Slightly off zero to avoid floating point logic flips at 90 and 270 deg. */ if (dx >= -0.00001) plptex(dx, dy, dx, dy, -0.15, text); else plptex(dx, dy, -dx, -dy, 1.15, text); } /* Draw the graph */ for (i = 0; i <= 360; i++) { r = sin(dtr * (5 * i)); x[i] = x0[i] * r; y[i] = y0[i] * r; } plcol0(3); plline(361, x, y); plcol0(4); plmtex("t", 2.0, 0.5, 0.5, "#frPLplot Example 3 - r(#gh)=sin 5#gh"); plflush(); }