示例#1
0
//--------------------------------------------------------------------------
//Actually draw the map lines points and text.
//--------------------------------------------------------------------------
void
drawmapdata( void ( *mapform )( PLINT, PLFLT *, PLFLT * ), int shapetype, PLINT n, PLFLT *x, PLFLT *y, PLFLT dx, PLFLT dy, PLFLT just, const char *text )
{
    PLINT i;

    //do the transform if needed
    if ( mapform != NULL )
        ( *mapform )( n, x, y );

    if ( shapetype == SHPT_ARC )
        plline( n, x, y );
    else if ( shapetype == SHPT_POINT )
        for ( i = 0; i < n; ++i )
            plptex( x[i], y[i], dx, dy, just, text );
    else if ( shapetype == SHPT_POLYGON )
        plfill( n, x, y );
#ifdef HAVE_SHAPELIB
    else if ( shapetype == SHPT_ARCZ || shapetype == SHPT_ARCM )
        plline( n, x, y );
    else if ( shapetype == SHPT_POLYGON || shapetype == SHPT_POLYGONZ || shapetype == SHPT_POLYGONM )
        plfill( n, x, y );
    else if ( shapetype == SHPT_POINT || shapetype == SHPT_POINTM || shapetype == SHPT_POINTZ )
        for ( i = 0; i < n; ++i )
            plptex( x[i], y[i], dx, dy, just, text );
#endif //HAVE_SHAPELIB
}
示例#2
0
void yaxis(
    real x0,
    real y0,    		/* axis starting point */
    real yl,		        /* axis length */
    real tick[],		/* tick values or limits */
    int nticks,		        /* number of ticks */
    axis_proc ytrans,		/* plotting transformation */
    string label		/* label for axis */
)
{
    int i;
    real t, y;
    char val[32];

    plmove(x0, y0);
    plline(x0, y0 + yl);
    for (i = 0; i < abs(nticks); i++) {
	if (nticks > 0)
	    t = tick[i];
	else
	    t = tick[0] + (i + 1) * (tick[1] - tick[0]) / (1.0 - nticks);
	y = (*ytrans)(t);
	if (label != NULL) {
	    plmove(x0 + ytikrt, y);
	    plline(x0 - ytiklf, y);
	    sprintf(val, "%-.*f", nydig, t);
	    trimval(val);
	    if (! formalaxis) {
		pljust(0);
		pltext(val, x0 - ynumlf, y, ysznum, 90.0);
	    } else {
		pljust(1);
		pltext(val, x0 - ynumlf, y, ysznum, 0.0);
	    }
	} else {
	    plmove(x0 - ytikrt, y);
	    plline(x0 + ytiklf, y);
	}
    }
    if (label != NULL && *label != 0) {
	if (! formalaxis) {
	    pljust(0);
	    pltext(label, x0 - ylablf, y0 + yl / 2, yszlab, 90.0);
	} else {
	    pljust(1);
#ifdef FUDGEAXIS
	    pltext(label, x0 - ylablf, y0 + yl - yszlab/4.0, yszlab, 0.0);
#else
	    pltext(label, x0 - ylablf, y0 + yl - yszlab/2.0, yszlab, 0.0);
#endif
	}
    }
    pljust(-1);
}
示例#3
0
void xaxis(
    real x0, real y0,	    /* axis starting point */
    real xl,		    /* axis length */
    real tick[],	    /* tick values or limits */
    int nticks,		    /* number of ticks */
    axis_proc xtrans,	    /* plotting transformation */
    string label	    /* label for axis */
)
{
    int i;
    real t, x;
    char val[32];

    plmove(x0, y0);
    plline(x0 + xl, y0);
    for (i = 0; i < abs(nticks); i++) {
	if (nticks > 0)
	    t = tick[i];
	else
	    t = tick[0] + (i + 1) * (tick[1] - tick[0]) / (1.0 - nticks);
	x = (*xtrans)(t);
	if (label != NULL) {
	    plmove(x, y0 + xtikup);
	    plline(x, y0 - xtikdn);
	    sprintf(val, "%-.*f", nxdig, t);
	    trimval(val);
	    pljust(0);
	    pltext(val, x, y0 - xnumdn, xsznum, 0.0);
	} else {
	    plmove(x, y0 - xtikup);
	    plline(x, y0 + xtikdn);
	}
    }
    if (label != NULL && *label != 0) {
	if (! formalaxis) {
	    pljust(0);
	    pltext(label, x0 + xl / 2, y0 - xlabdn, xszlab, 0.0);
	} else {
	    pljust(1);
#ifdef FUDGEAXIS
	    pltext(label, x0 + xl, y0 - xlabdn + xszlab/4.0, xszlab, 0.0);
#else
	    pltext(label, x0 + xl, y0 - xlabdn, xszlab, 0.0);
#endif
	}
    }
    pljust(-1);
}
示例#4
0
void
plot2(void)
{
    int i;

/* Set up the viewport and window using PLENV. The range in X is -2.0 to
   10.0, and the range in Y is -0.4 to 2.0. The axes are scaled separately
   (just = 0), and we draw a box with axes (axis = 1). */

    plcol(1);
    plenv((PLFLT) -2.0, (PLFLT) 10.0, (PLFLT) -0.4, (PLFLT) 1.2, 0, 1);
    plcol(2);
    pllab("(x)", "sin(x)/x", "#frPLplot Example 1 - Sinc Function");

/* Fill up the arrays */

    for (i = 0; i < 100; i++) {
	x[i] = (i - 19.0) / 6.0;
	y[i] = 1.0;
	if (x[i] != 0.0)
	    y[i] = sin(x[i]) / x[i];
    }

/* Draw the line */

    plcol(3);
    plline(100, x, y);

}
示例#5
0
static void plstrip_gen( PLStrip *strip )
{
    int i;
    PLFLT x[]={0.,1.,1.,0.}, y[]={0.,0.,1.,1.};

/* Set up window */

    plvpor(0,1,0,1);
    plwind(0,1,0,1);
    plcol(0);plpsty(0);
    plfill(4, &x[0], &y[0]);
    plvsta();

/* Draw box and same window dimensions */
    strip->wxmin=strip->xmin; strip->wxmax=strip->xmax;
    strip->wymin=strip->ymin; strip->wymax=strip->ymax; /* FIXME - can exist some redundancy here */

    plwind(strip->xmin, strip->xmax, strip->ymin, strip->ymax);

    pllsty(1);
    plcol(strip->colbox);
    plbox(strip->xspec, 0.0, 0, strip->yspec, 0.0, 0);

    plcol(strip->collab);
    pllab(strip->labx, strip->laby, strip->labtop);

    for (i=0; i<PEN; i++) {
        if (strip->npts[i] > 0) {
            plcol(strip->colline[i]);pllsty(strip->styline[i]);
            plline(strip->npts[i], strip->x[i], strip->y[i]);
        }
    }

    plstrip_legend(strip,0);
}
示例#6
0
void
plot2( void )
{
    int i;

// Set up the viewport and window using PLENV. The range in X is -2.0 to
// 10.0, and the range in Y is -0.4 to 2.0. The axes are scaled separately
// (just = 0), and we draw a box with axes (axis = 1).
//
    plcol0( 1 );
    plenv( -2.0, 10.0, -0.4, 1.2, 0, 1 );
    plcol0( 2 );
    pllab( "(x)", "sin(x)/x", "#frPLplot Example 1 - Sinc Function" );

// Fill up the arrays

    for ( i = 0; i < 100; i++ )
    {
        x[i] = ( i - 19.0 ) / 6.0;
        y[i] = 1.0;
        if ( x[i] != 0.0 )
            y[i] = sin( x[i] ) / x[i];
    }

// Draw the line

    plcol0( 3 );
    plwidth( 2 );
    plline( 100, x, y );
    plwidth( 1 );
}
示例#7
0
void setup_plot_drawable( App *a )
{
    struct
    {
        Display  *display;
        Drawable drawable;
    }     xinfo;

    PLFLT x[3] = { 1, 3, 4 };
    PLFLT y[3] = { 3, 2, 5 };

    plsdev( "xcairo" );
    plsetopt( "drvopt", "external_drawable" );
    plinit();

  #if TO_PIXMAP == 1
    // Here we set up to draw to a pixmap
    xinfo.display  = GDK_PIXMAP_XDISPLAY( a->plotwindow_pixmap );
    xinfo.drawable = GDK_PIXMAP_XID( a->plotwindow_pixmap );
  #else
    // Alternatively, we can do direct to a visible X Window
    xinfo.display  = GDK_WINDOW_XDISPLAY( a->plotwindow->window );
    xinfo.drawable = GDK_WINDOW_XID( a->plotwindow->window );
  #endif

    pl_cmd( PLESC_DEVINIT, &xinfo );
    plenv( 0, 5, 0, 5, 0, 0 );

    plline( 3, x, y );
    plend();
}
示例#8
0
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;
}
示例#9
0
static void polar( void )
//polar contour plot example.
{
    int      i, j;
    PLcGrid2 cgrid2;
    PLFLT    **z;
    PLFLT    px[PERIMETERPTS], py[PERIMETERPTS];
    PLFLT    t, r, theta;
    PLFLT    lev[10];

    plenv( -1., 1., -1., 1., 0, -2 );
    plcol0( 1 );

//Perimeter
    for ( i = 0; i < PERIMETERPTS; i++ )
    {
        t     = ( 2. * M_PI / ( PERIMETERPTS - 1 ) ) * (double) i;
        px[i] = cos( t );
        py[i] = sin( t );
    }
    plline( PERIMETERPTS, px, py );

//create data to be contoured.
    plAlloc2dGrid( &cgrid2.xg, RPTS, THETAPTS );
    plAlloc2dGrid( &cgrid2.yg, RPTS, THETAPTS );
    plAlloc2dGrid( &z, RPTS, THETAPTS );
    cgrid2.nx = RPTS;
    cgrid2.ny = THETAPTS;

    for ( i = 0; i < RPTS; i++ )
    {
        r = i / (double) ( RPTS - 1 );
        for ( j = 0; j < THETAPTS; j++ )
        {
            theta           = ( 2. * M_PI / (double) ( THETAPTS - 1 ) ) * (double) j;
            cgrid2.xg[i][j] = r * cos( theta );
            cgrid2.yg[i][j] = r * sin( theta );
            z[i][j]         = r;
        }
    }

    for ( i = 0; i < 10; i++ )
    {
        lev[i] = 0.05 + 0.10 * (double) i;
    }

    plcol0( 2 );
    plcont( (const PLFLT * const *) z, RPTS, THETAPTS, 1, RPTS, 1, THETAPTS, lev, 10,
        pltr2, (void *) &cgrid2 );
    plcol0( 1 );
    pllab( "", "", "Polar Contour Plot" );
    plFree2dGrid( z, RPTS, THETAPTS );
    plFree2dGrid( cgrid2.xg, RPTS, THETAPTS );
    plFree2dGrid( cgrid2.yg, RPTS, THETAPTS );
}
/* basic "plot one line" atom */
static void plotOneLine(
    uint32_t numSamples,
    PLFLT *fx,
    LineDef *lineDef,
    bool plotPoints,		/* true: plot points */
    bool plotLine)			/* true: plot line */
{
    /* set drawing color - set the value for color map 0[1], then set it */
    const RGB *rgb = &plColors[lineDef->color];
    plscol0(1, rgb->r, rgb->g, rgb->b);
    plcol0(1);

    if(plotPoints) {
        plpoin(numSamples, fx, lineDef->fy, lineDef->pointCode);
    }
    if(plotLine) {
        plline(numSamples, fx, lineDef->fy);
    }
}
示例#11
0
void
plot1( void )
{
    int   i;
    PLFLT xmin, xmax, ymin, ymax;

    for ( i = 0; i < 60; i++ )
    {
        x[i] = xoff + xscale * ( i + 1 ) / 60.0;
        y[i] = yoff + yscale * pow( x[i], 2. );
    }

    xmin = x[0];
    xmax = x[59];
    ymin = y[0];
    ymax = y[59];

    for ( i = 0; i < 6; i++ )
    {
        xs1[i] = x[i * 10 + 3];
        ys1[i] = y[i * 10 + 3];
    }

// Set up the viewport and window using PLENV. The range in X is
// 0.0 to 6.0, and the range in Y is 0.0 to 30.0. The axes are
// scaled separately (just = 0), and we just draw a labelled
// box (axis = 0).

    plcol0( 1 );
    plenv( xmin, xmax, ymin, ymax, 0, 0 );
    plcol0( 6 );
    pllab( "(x)", "(y)", "#frPLplot Example 1 - y=x#u2" );

// Plot the data points

    plcol0( 9 );
    plpoin( 6, xs1, ys1, 9 );

// Draw the line through the data

    plcol0( 4 );
    plline( 60, x, y );
}
示例#12
0
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 );
}
示例#13
0
void plot_path(orbitptr o, real tstart, real tend, int n)
{
	int i, plotfirst = 1;
	real x,y;

	for (i=0; i<(Nsteps(o)-n); i += n) {
	    if ((tstart<Torb(optr,i)) && (Torb(optr,i)<tend)) {
		x = xtrans(Posorb(o,i,xvar_idx));
		y = ytrans(Posorb(o,i,yvar_idx));
		if (plotfirst) {
		    plpoint (x,y);			/* mark first point */
	 	    plotfirst = 0;
		}
		plmove (x,y);
		x = xtrans(Posorb(o,i+n,xvar_idx));
		y = ytrans(Posorb(o,i+n,yvar_idx));
		plline (x,y);
	     }
	}
}
示例#14
0
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 );
}
示例#15
0
int main( int argc, const char *argv[] )
{

	PLFLT x[NSIZE], y[NSIZE];
	PLFLT xmin = 0., xmax = 1., ymin = 0., ymax = 100.;

	for (int i = 0; i < NSIZE; i++)
	{
		x[i] = (PLFLT) (i) / (PLFLT) (NSIZE-1);
		y[i] = ymax * x[i] * x[i];
	}

	plparseopts( &argc, argv, PL_PARSE_FULL );

	plinit();
	plenv(xmin, xmax, ymin, ymax, 0, 0);
	pllab("x", "y", "Simple PLplot demo of a 2D line plot");
	plline(NSIZE, x, y);

	plend();

	return 0;
}
示例#16
0
void plplot_plot_xy(plot_driver_type * driver     , 
                    const char * label , 
                    double_vector_type * x  , 
                    double_vector_type * y  , 
                    plot_style_type style         , 
                    line_attribute_type line_attr , 
                    point_attribute_type point_attr) {

  int size = double_vector_size( x );

  plplot_logtransform_x( driver , x );
  plplot_logtransform_y( driver , y );
  
  /* 
     Special case: 
     -------------
     If only one single point AND plot_style == LINE, we
     effectively change the plot_style to POINTS (and use the
     line_color) - otherwise the single point will not be visible.
  */
  
  if ((style == LINE) && (size == 1)) {
    style                  = POINTS;
    point_attr.point_color = line_attr.line_color;
  }
  
  if (style & LINE) {
    plplot_setup_linestyle( line_attr );
    plline(size , double_vector_get_ptr(x) , double_vector_get_ptr(y));
  }

  if (style & POINTS) {
    plplot_setup_pointstyle( point_attr );
    plpoin(size , double_vector_get_ptr(x) , double_vector_get_ptr(y) , point_attr.symbol_type);
  }
}
示例#17
0
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 );
}
示例#18
0
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;
}
示例#19
0
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;
}
示例#20
0
void
plot1( int do_test )
{
    int   i;
    PLFLT xmin, xmax, ymin, ymax;

    for ( i = 0; i < 60; i++ )
    {
        x[i] = xoff + xscale * ( i + 1 ) / 60.0;
        y[i] = yoff + yscale * pow( x[i], 2. );
    }

    xmin = x[0];
    xmax = x[59];
    ymin = y[0];
    ymax = y[59];

    for ( i = 0; i < 6; i++ )
    {
        xs[i] = x[i * 10 + 3];
        ys[i] = y[i * 10 + 3];
    }

// Set up the viewport and window using PLENV. The range in X is
// 0.0 to 6.0, and the range in Y is 0.0 to 30.0. The axes are
// scaled separately (just = 0), and we just draw a labelled
// box (axis = 0).
//
    plcol0( 1 );
    plenv( xmin, xmax, ymin, ymax, 0, 0 );
    plcol0( 2 );
    pllab( "(x)", "(y)", "#frPLplot Example 1 - y=x#u2" );

// Plot the data points

    plcol0( 4 );
    plpoin( 6, xs, ys, 9 );

// Draw the line through the data

    plcol0( 3 );
    plline( 60, x, y );

// xor mode enable erasing a line/point/text by replotting it again
// it does not work in double buffering mode, however

    if ( do_test && test_xor )
    {
#ifdef PL_HAVE_NANOSLEEP
        PLINT           st;
        struct timespec ts;
        ts.tv_sec  = 0;
        ts.tv_nsec = 50000000;
        plxormod( 1, &st ); // enter xor mode
        if ( st )
        {
            for ( i = 0; i < 60; i++ )
            {
                plpoin( 1, x + i, y + i, 9 );   // draw a point
                nanosleep( &ts, NULL );         // wait a little
                plflush();                      // force an update of the tk driver
                plpoin( 1, x + i, y + i, 9 );   // erase point
            }
            plxormod( 0, &st );                 // leave xor mode
        }
#else
        printf( "The -xor command line option can only be exercised if your "
            "system\nhas nanosleep(), which does not seem to happen.\n" );
#endif
    }
}
示例#21
0
nemo_main()
{
    int i, j, np;
    string name, dumpfile;

    name = getparam("name");
    dumpfile = getparam("screendump");
    np = getiparam("pages");
    printf("Testing wth pages=%d\n",np);
    plinit(name, 0.0, 20.0, 0.0, 20.0);     /* open device */
    x_init_plobj();
    plmove(0.0, 0.0);
    plcolor(0);
    plline(20.0, 0.0);
    plcolor(1);
    plline(20.0, 20.0);
    plcolor(2);
    plline(0.0, 20.0);
    plcolor(3);
    plline(0.0, 0.0);
    plcolor(4);
    plline(20.0, 20.0);
    plmove(20.0, 0.0);
    plcolor(5);
    plline(0.0, 20.0);
    plltype(12, 0);
    plmove(4.0, 18.0);
    plcolor(6);
    plline(16.0, 18.0);
    plltype(-6, 0);
    plmove(6.0, 18.0);
    plcolor(7);
    plline(14.0, 18.0);
    
    for (i = 1; i <= 4; i++) {
	plcolor(8+i);
	plltype(i, 1);
        plmove(1.0, 13.0 - i);
        plline(3.0, 13.0 - i);
        plpoint(3.5, 13.0 - i);
	plltype(1, i);
	for (j = 1; j <= 4; j++) {
	    plmove(1.5, 13.0 - i - 0.2*j);
	    plline(1.5 + j, 13.0 - i - 0.2*j);
	}
    }
    plcolor(12);
    plltype(1, 1);
    plcircle(15.0, 9.0, -0.5);
    plcolor(13);
    plcircle(16.0, 9.0, 0.25);
    plcolor(14);
    plcircle(17.0, 9.0, 0.125);
    plcolor(15);
    plcircle(18.0, 9.0, 0.0625);
    plbox(16.0, 8.0, 0.4);
    plbox(17.0, 8.0, 0.2);
    plbox(18.0, 8.0, -0.2);
    plcross(16.0, 7.0, 0.4);
    plcross(17.0, 7.0, 0.2);
    plcross(18.0, 7.0, -0.2);
    plcolor(4);
    pltext("Foo Bar!", 8.0, 5.0, 0.5, 0.0);
    plcolor(5);
    pltext("Fum Bar!", 8.0, 3.0, 0.25, 0.0);
    plcolor(6);
    for (i = 0; i <= 4; i++)
	pltext(" testing angles", 16.0, 10.0, 0.2, 45.0*i);
    plmove(10.0, 8.5);
    plline(10.0, 11.5);
    pljust(-1);
    plcolor(3);
    pltext("left justified",  10.0,  9.0, 0.25, 0.0);
    plcolor(2);
    pljust(0);
    pltext("centered",        10.0, 10.0, 0.25, 0.0);
    plcolor(1);
    pljust(1);
    pltext("right justified", 10.0, 11.0, 0.25, 0.0);
    pljust(0);
    plcolor(7);
    pltext(getparam("headline"),10.0, 19.0, 0.5, 0.0);
    plcolor(1);
    plflush();
    if (*dumpfile)
        pl_screendump(dumpfile);
    if (np>1) {
        plflush();
        plframe();
        plmove(0.0, 0.0);
        plline(20.0, 0.0);
        plline(20.0, 20.0);
        plline(0.0, 20.0);
        plline(0.0, 0.0);

        pljust(0);
        pltext("This is page 2", 10.0,10.0,0.25,0.0);

#define IMAX 100
#define ISTEP 20.0/IMAX

        plmove (0.0,0.0);
        for (i=0; i<IMAX; i++)
           plline(i*ISTEP, i*ISTEP);
    }
    plstop();
}
示例#22
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 );
}
示例#23
0
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);
}
示例#24
0
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 );
}
示例#25
0
out_slit()
{
    real xsky, ysky, vrad, inv_surden, sigma, mass;
    real xslit, yslit, xplt, yplt, sinpa, cospa;
    real m_max, v_min, v_max, s_max;	      /* local min/max */
    int    i, islit;
    Body *bp;

    for (islit=0; islit<nslit; islit++)     /* reset local variables */
	v0star[islit] = v1star[islit] = v2star[islit] = 0.0;
    m_max = v_min = v_max = s_max = 0.0;
    inv_surden = 1.0 / (slit_width*slit_cell);
    sinpa = sin(pa); cospa = cos(pa);

    for(bp=btab, i=0; i<nobj; bp++, i++) {      /* loop over all particles */
 	xsky = xvar(bp,tsnap,i);
 	ysky = yvar(bp,tsnap,i);
 	vrad = zvar(bp,tsnap,i);
 	mass = evar(bp,tsnap,i) * inv_surden;
 	
	xsky -= origin[0];			/* translate to slit origin */
	ysky -= origin[1];
	xslit = -cospa*ysky + sinpa*xsky;	/* and rotate to slit frame */
	yslit =  sinpa*ysky + cospa*xsky;	/* !!! check signs !!! */

	if (fabs(yslit) > 0.5*slit_width) 
	   continue;			/* not in slit */

	islit =  (xslit+0.5*slit_length)/slit_cell;
	if (islit<0 || islit>=nslit)
	   continue;			/* not in slit */

	v0star[islit] += mass;
	v1star[islit] += vrad * mass;
	v2star[islit] += sqr(vrad) * mass;
     } /*-- end particles loop --*/


     while (nsmooth-- > 0) {            	/* convolution */
     	dprintf (0,"Convolving with %d-length beam: ",lsmooth);
     	for (i=0; i<lsmooth; i++) 
            dprintf (0,"%f ",smooth[i]);
    	convolve (v0star, nslit, smooth, lsmooth);
    	convolve (v1star, nslit, smooth, lsmooth);
    	convolve (v2star, nslit, smooth, lsmooth);
     	dprintf (0,"\n");
    }
    	
    for (islit=0; islit<nslit; islit++) { /* moment analysis: M, MV and MV^2 */
	if (v0star[islit]==0.0)
	    continue;		/* no data - skip to next pixel */
	v1star[islit] /= v0star[islit];
	sigma = v2star[islit]/v0star[islit] - sqr(v1star[islit]);
	if (sigma<0.0) {        /* should never happen */
	    warning("islit=%d sigma^2=%e < 0 !!!\n",islit,sigma);
	    v2star[islit] = 0.0;
	    continue;		/* something really wrong */
	}
	v2star[islit] = sqrt(sigma);

	if (v0star[islit] > m_max)  m_max = v0star[islit];
	if (v1star[islit] < v_min)  v_min = v1star[islit];
	if (v1star[islit] > v_max)  v_max = v1star[islit];
	if (v2star[islit] > s_max)  s_max = v2star[islit];
	if (Qtab) {
	    xslit = islit*slit_cell;
	    printf ("%g %g %g %g\n",
			xslit,v0star[islit], v1star[islit], v2star[islit]);
	}
    } /* for(islit) */
 
    if (Qtab)
        return(0);

    plinit ("***", 0.0, 20.0, 0.0, 20.0);

	/* reset default autoscales to user supplied if necessary */
    if (mmax==0.0) mmax=m_max;
    if (vmin==0.0) vmin=v_min;
    if (vmax==0.0) vmax=v_max;
    if (smax==0.0) smax=s_max;
    dprintf (0,"mmax=%f vmin=%f vmax=%f smax=%f  reset to:\n",m_max,v_min,v_max,s_max);
    if (mmax==0) mmax=1;
    if (vmin==0 && vmax==0) vmax=1;
    if (smax==0) smax=1;
    dprintf (0,"mmax=%f vmin=%f vmax=%f smax=%f           \n",mmax, vmin, vmax, smax);
    
	/* general plot header */
    sprintf (plabel,"File: %s; var{%s,%s,%s,%s} slit{%s %s %s %s}",
		infile,getparam("xvar"),getparam("yvar"),
		getparam("zvar"),getparam("evar"),
		getparam("origin"),getparam("pa"),getparam("width"),
		getparam("length"),getparam("cell"));
		
    pltext (plabel,2.0,18.4, 0.32, 0.0);
#if 0
    if (*headline!=NULL)				/* identification */
	pltext (headline,2.0,19.0,0.25,0.0);
#endif

    xplot[0] = -0.5*slit_length;            /* PLOT1: upper panel */
    xplot[1] =  0.5*slit_length;
    sprintf(xlabel,"slit: {x=%s,y=%s}",getparam("xvar"),getparam("yvar"));

    yplot[0]=0.0; 
    yplot[1]=mmax;  
    strcpy (ylabel,"mass surface density");

    xaxis ( 2.0,12.0, 16.0, xplot, -7, xtrans,  NULL);
    xaxis ( 2.0,17.0, 16.0, xplot, -7, xtrans,  NULL);
    yaxis ( 2.0,12.0,  5.0, yplot, -3, ytransm, ylabel);
    yaxis (18.0,12.0,  5.0, yplot, -3, ytransm, NULL);

    for (islit=0; islit<nslit; islit++) {
	xplt = xtrans (-0.5*slit_length + (islit+0.5)*slit_cell);
	yplt = ytransm (v0star[islit]);
	plbox (xplt, yplt, SYMBOLSIZE);
    }
                                           
    yplot[0]=vmin;                      /* PLOT2: middle panel */
    yplot[1]=vmax;  
    strcpy (ylabel,"velocity");

    xaxis (2.0, 7.0, 16.0, xplot, -7, xtrans,   NULL);	/* line ?? */
    yaxis (2.0, 7.0,  5.0, yplot, -3, ytransv1, ylabel);
    yaxis (18.0,7.0,  5.0, yplot, -3, ytransv1, NULL);

    for (islit=0; islit<nslit; islit++) {
	xplt = xtrans (-0.5*slit_length + (islit+0.5)*slit_cell);
	yplt = ytransv1 (v1star[islit]);
	plcross (xplt, yplt, SYMBOLSIZE);
    }
    if (vmin<0.0 || vmax>0.0) {
       plltype (1,2);	/* dashed line at v=0 */
       plmove (xtrans(xplot[0]), ytransv1(0.0));
       plline (xtrans(xplot[1]), ytransv1(0.0));
       plltype (1,1);
    }

    yplot[0]=0.0;                       /* PLOT3: bottom panel */
    yplot[1]=smax; 
    strcpy (ylabel,"velocity dispersion");
    xaxis (2.0, 2.0, 16.0, xplot, -7, xtrans,   xlabel);
    yaxis (2.0, 2.0,  5.0, yplot, -3, ytransv2, ylabel);
    yaxis (18.0,2.0,  5.0, yplot, -3, ytransv2, NULL);

    for (islit=0; islit<nslit; islit++) {
	xplt = xtrans (-0.5*slit_length + (islit+0.5)*slit_cell);
	yplt = ytransv2 (v2star[islit]);
	plcross (xplt, yplt, -SYMBOLSIZE);
    }

    plstop();
}
示例#26
0
void
plmeridians( void ( *mapform )( PLINT, PLFLT *, PLFLT * ),
             PLFLT dlong, PLFLT dlat,
             PLFLT minlong, PLFLT maxlong, PLFLT minlat, PLFLT maxlat )
{
    PLFLT yy, xx, temp, x[2], y[2], dx, dy;

    if ( minlong > maxlong )
    {
        temp    = minlong;
        minlong = maxlong;
        maxlong = temp;
    }
    if ( minlat > maxlat )
    {
        temp   = minlat;
        minlat = maxlat;
        maxlat = temp;
    }
    dx = ( maxlong - minlong ) / NSEG;
    dy = ( maxlat - minlat ) / NSEG;

    // latitudes

    for ( yy = dlat * ceil( minlat / dlat ); yy <= maxlat; yy += dlat )
    {
        if ( mapform == NULL )
        {
            plpath( NSEG, minlong, yy, maxlong, yy );
        }
        else
        {
            for ( xx = minlong; xx < maxlong; xx += dx )
            {
                y[0] = y[1] = yy;
                x[0] = xx;
                x[1] = xx + dx;
                ( *mapform )( 2, x, y );
                plline( 2, x, y );
            }
        }
    }

    // longitudes

    for ( xx = dlong * ceil( minlong / dlong ); xx <= maxlong; xx += dlong )
    {
        if ( mapform == NULL )
        {
            plpath( NSEG, xx, minlat, xx, maxlat );
        }
        else
        {
            for ( yy = minlat; yy < maxlat; yy += dy )
            {
                x[0] = x[1] = xx;
                y[0] = yy;
                y[1] = yy + dy;
                ( *mapform )( 2, x, y );
                plline( 2, x, y );
            }
        }
    }
}
示例#27
0
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 );
}
示例#28
0
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 );
}
示例#29
0
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);
}
示例#30
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
}