Example #1
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);

}
    void RendererPlplot::draw_plot(const data::Plot &plot)
    {
      switch (plot.get_dimensions())
        {
        case 1:
          // FIXME
          set_2d_plot_window(plot);

          pl_set_plot_window();
          pl_draw_axes(plot.get_axes());

          _pls->col0(get_color_id(get_style_color(StyleForeground)));

          pllab((char*)plot.get_axes().get_label(0).c_str(),
                (char*)plot.get_axes().get_label(1).c_str(),
                (char*)plot.get_title().c_str());

          for (unsigned int i = 0; i < plot.get_plot_count(); i++)
            {
              const data::Plotdata &d = plot.get_plot_data(i);
              draw_plot_data_2d(static_cast<const data::Set1d&>(d.get_set()), d);
            }

          pl_set_drawing_window();
          break;

        default:
          RendererViewport::draw_plot(plot);
        }
    }
Example #3
0
static void
plot3( void )
{
    static PLFLT xx[2][5] = { { -1.0, 1.0, 1.0, -1.0, -1.0 },
                              { -1.0, 1.0, 1.0, -1.0, -1.0 } };
    static PLFLT yy[2][5] = { {  1.0,  1.0, 0.0, 0.0,  1.0 },
                              { -1.0, -1.0, 0.0, 0.0, -1.0 } };
    static PLFLT zz[2][5] = { { 0.0, 0.0, 1.0, 1.0, 0.0 },
                              { 0.0, 0.0, 1.0, 1.0, 0.0 } };

    pladv( 0 );
    plvpor( 0.1, 0.9, 0.1, 0.9 );
    plwind( -1.0, 1.0, -1.0, 1.0 );
    plw3d( 1., 1., 1., -1.0, 1.0, -1.0, 1.0, 0.0, 1.5, 30, -40 );

/* Plot using identity transform */

    plcol0( 1 );
    plbox3( "bntu", "X", 0.0, 0, "bntu", "Y", 0.0, 0, "bcdfntu", "Z", 0.5, 0 );
    plcol0( 2 );
    pllab( "", "", "3-d polygon filling" );

    plcol0( 3 );
    plpsty( 1 );
    plline3( 5, xx[0], yy[0], zz[0] );
    plfill3( 4, xx[0], yy[0], zz[0] );
    plpsty( 2 );
    plline3( 5, xx[1], yy[1], zz[1] );
    plfill3( 4, xx[1], yy[1], zz[1] );
}
Example #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).
//
    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 );
}
Example #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);
}
Example #6
0
static void
plot1( void )
{
    PLFLT shade_min, shade_max, sh_color;
    PLINT sh_cmap   = 0, sh_width;
    PLINT min_color = 0, min_width = 0, max_color = 0, max_width = 0;

    pladv( 0 );
    plvpor( 0.1, 0.9, 0.1, 0.9 );
    plwind( -1.0, 1.0, -1.0, 1.0 );

/* Plot using identity transform */

    shade_min = zmin + ( zmax - zmin ) * 0.4;
    shade_max = zmin + ( zmax - zmin ) * 0.6;
    sh_color  = 7;
    sh_width  = 2;
    min_color = 9;
    max_color = 2;
    min_width = 2;
    max_width = 2;

    plpsty( 8 );
    plshade1( &z[0][0], XPTS, YPTS, NULL, -1., 1., -1., 1.,
        shade_min, shade_max,
        sh_cmap, sh_color, sh_width,
        min_color, min_width, max_color, max_width,
        plfill, 1, NULL, NULL );

    plcol0( 1 );
    plbox( "bcnst", 0.0, 0, "bcnstv", 0.0, 0 );
    plcol0( 2 );
    pllab( "distance", "altitude", "Bogon flux" );
}
Example #7
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 );
}
Example #8
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 );
}
Example #9
0
static void
plot2( void )
{
    PLFLT        shade_min, shade_max, sh_color;
    PLINT        sh_cmap   = 0, sh_width;
    PLINT        min_color = 0, min_width = 0, max_color = 0, max_width = 0;
    int          i;
    static PLINT nlin[10]   = { 1, 1, 1, 1, 1, 2, 2, 2, 2, 2 };
    static PLINT inc[10][2] = { { 450,    0 }, { -450,    0 }, { 0,   0 }, { 900,   0 },
                                { 300,    0 }, {  450, -450 }, { 0, 900 }, {   0, 450 },
                                { 450, -450 }, {    0,  900 } };
    static PLINT del[10][2] = { { 2000, 2000 }, { 2000, 2000 }, { 2000, 2000 },
                                { 2000, 2000 }, { 2000, 2000 }, { 2000, 2000 },
                                { 2000, 2000 }, { 2000, 2000 }, { 4000, 4000 },
                                { 4000, 2000 } };

    sh_width = 2;

    pladv( 0 );
    plvpor( 0.1, 0.9, 0.1, 0.9 );
    plwind( -1.0, 1.0, -1.0, 1.0 );

/* Plot using identity transform */

    for ( i = 0; i < 10; i++ )
    {
        shade_min = zmin + ( zmax - zmin ) * i / 10.0;
        shade_max = zmin + ( zmax - zmin ) * ( i + 1 ) / 10.0;
        sh_color  = i + 6;
        plpat( nlin[i], inc[i], del[i] );

        plshade1( &z[0][0], XPTS, YPTS, NULL, -1., 1., -1., 1.,
            shade_min, shade_max,
            sh_cmap, sh_color, sh_width,
            min_color, min_width, max_color, max_width,
            plfill, 1, NULL, NULL );
    }

    plcol0( 1 );
    plbox( "bcnst", 0.0, 0, "bcnstv", 0.0, 0 );
    plcol0( 2 );
    pllab( "distance", "altitude", "Bogon flux" );
}
Example #10
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 );
}
Example #11
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 );
}
int main( int argc, const char *argv[] )
{
    cairo_surface_t *cairoSurface;
    cairo_t         *cairoContext;

    cairoSurface = cairo_ps_surface_create( "ext-cairo-test.ps", 720, 540 );
    cairoContext = cairo_create( cairoSurface );

    plparseopts( &argc, argv, PL_PARSE_FULL );

    plsdev( "extcairo" );
    plinit();
    pl_cmd( PLESC_DEVINIT, cairoContext );
    plenv( 0.0, 1.0, 0.0, 1.0, 1, 0 );
    pllab( "x", "y", "title" );
    plend();

    cairo_destroy( cairoContext );
    cairo_surface_destroy( cairoSurface );
    exit( 0 );
}
Example #13
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;
}
Example #14
0
void
plot5(void)
{
    int i, j;
    PLFLT xx, yy;
    PLFLT **z, **w;
    static PLINT mark = 1500, space = 1500;

/* Set up function arrays */

    plAlloc2dGrid(&z, XPTS, YPTS);
    plAlloc2dGrid(&w, XPTS, YPTS);

    for (i = 0; i < XPTS; i++) {
	xx = (double) (i - (XPTS / 2)) / (double) (XPTS / 2);
	for (j = 0; j < YPTS; j++) {
	    yy = (double) (j - (YPTS / 2)) / (double) (YPTS / 2) - 1.0;
	    z[i][j] = xx * xx - yy * yy;
	    w[i][j] = 2 * xx * yy;
	}
    }

    plenv(-1.0, 1.0, -1.0, 1.0, 0, 0);
    plcol0(2);
    plcont(z, XPTS, YPTS, 1, XPTS, 1, YPTS, clevel, 11, mypltr, NULL);
    plstyl(1, &mark, &space);
    plcol0(3);
    plcont(w, XPTS, YPTS, 1, XPTS, 1, YPTS, clevel, 11, mypltr, NULL);
    plcol0(1);
    pllab("X Coordinate", "Y Coordinate", "Streamlines of flow");
    plflush();

/* Clean up */
    plFree2dGrid(z, XPTS, YPTS);
    plFree2dGrid(w, XPTS, YPTS);

}
Example #15
0
void draw_page( PLINT mode, const char *title )
{
    PLFLT xs[3], ys[3];
    PLFLT over_x, over_y, over_r;

    // A triangle for the background
    xs[0] = 0.0;
    xs[1] = 1.0;
    xs[2] = 0.0;
    ys[0] = 0.0;
    ys[1] = 1.0;
    ys[2] = 1.0;

    // A circle for the foreground
    over_x = 0.5;
    over_y = 0.5;
    over_r = 0.4;

    plcol0( 1 );

    // Setup a plot window
    plenv( 0.0, 1.0, 0.0, 1.0, 1, 0 );

    // Show which mode we're using
    pllab( "", "", title );

    // Draw a background triangle using the default drawing mode
    plcol0( 2 );
    plsdrawmode( PL_DRAWMODE_DEFAULT );
    plfill( 3, xs, ys );

    // Draw a circle in the given drawing mode
    plcol0( 3 );
    plsdrawmode( mode );
    plarc( over_x, over_y, over_r, over_r, 0.0, 360.0, 0.0, 1 );
}
Example #16
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 );
}
Example #17
0
int
main( int argc, const char *argv[] )
{
    int          i, j;
    PLFLT        xx, yy, argx, argy, distort;
    static PLINT mark = 1500, space = 1500;

    PLFLT        **z, **w;
    PLFLT        xg1[XPTS], yg1[YPTS];
    PLcGrid      cgrid1;
    PLcGrid2     cgrid2;

// Parse and process command line arguments

    (void) plparseopts( &argc, argv, PL_PARSE_FULL );

// Initialize plplot

    plinit();

// Set up function arrays

    plAlloc2dGrid( &z, XPTS, YPTS );
    plAlloc2dGrid( &w, XPTS, YPTS );

    for ( i = 0; i < XPTS; i++ )
    {
        xx = (double) ( i - ( XPTS / 2 ) ) / (double) ( XPTS / 2 );
        for ( j = 0; j < YPTS; j++ )
        {
            yy      = (double) ( j - ( YPTS / 2 ) ) / (double) ( YPTS / 2 ) - 1.0;
            z[i][j] = xx * xx - yy * yy;
            w[i][j] = 2 * xx * yy;
        }
    }

// Set up grids

    cgrid1.xg = xg1;
    cgrid1.yg = yg1;
    cgrid1.nx = XPTS;
    cgrid1.ny = YPTS;

    plAlloc2dGrid( &cgrid2.xg, XPTS, YPTS );
    plAlloc2dGrid( &cgrid2.yg, XPTS, YPTS );
    cgrid2.nx = XPTS;
    cgrid2.ny = YPTS;

    for ( i = 0; i < XPTS; i++ )
    {
        for ( j = 0; j < YPTS; j++ )
        {
            mypltr( (PLFLT) i, (PLFLT) j, &xx, &yy, NULL );

            argx    = xx * M_PI / 2;
            argy    = yy * M_PI / 2;
            distort = 0.4;

            cgrid1.xg[i] = xx + distort * cos( argx );
            cgrid1.yg[j] = yy - distort * cos( argy );

            cgrid2.xg[i][j] = xx + distort * cos( argx ) * cos( argy );
            cgrid2.yg[i][j] = yy - distort * cos( argx ) * cos( argy );
        }
    }

// Plot using identity transform
//
//  plenv(-1.0, 1.0, -1.0, 1.0, 0, 0);
//  plcol0(2);
//  plcont(z, XPTS, YPTS, 1, XPTS, 1, YPTS, clevel, 11, mypltr, NULL);
//  plstyl(1, &mark, &space);
//  plcol0(3);
//  plcont(w, XPTS, YPTS, 1, XPTS, 1, YPTS, clevel, 11, mypltr, NULL);
//  plstyl(0, &mark, &space);
//  plcol0(1);
//  pllab("X Coordinate", "Y Coordinate", "Streamlines of flow");
//
    pl_setcontlabelformat( 4, 3 );
    pl_setcontlabelparam( 0.006, 0.3, 0.1, 1 );
    plenv( -1.0, 1.0, -1.0, 1.0, 0, 0 );
    plcol0( 2 );
    plcont( (const PLFLT * const *) z, XPTS, YPTS, 1, XPTS, 1, YPTS, clevel, 11, mypltr, NULL );
    plstyl( 1, &mark, &space );
    plcol0( 3 );
    plcont( (const PLFLT * const *) w, XPTS, YPTS, 1, XPTS, 1, YPTS, clevel, 11, mypltr, NULL );
    plstyl( 0, &mark, &space );
    plcol0( 1 );
    pllab( "X Coordinate", "Y Coordinate", "Streamlines of flow" );
    pl_setcontlabelparam( 0.006, 0.3, 0.1, 0 );

// Plot using 1d coordinate transform

    plenv( -1.0, 1.0, -1.0, 1.0, 0, 0 );
    plcol0( 2 );
    plcont( (const PLFLT * const *) z, XPTS, YPTS, 1, XPTS, 1, YPTS, clevel, 11,
        pltr1, (void *) &cgrid1 );

    plstyl( 1, &mark, &space );
    plcol0( 3 );
    plcont( (const PLFLT * const *) w, XPTS, YPTS, 1, XPTS, 1, YPTS, clevel, 11,
        pltr1, (void *) &cgrid1 );
    plstyl( 0, &mark, &space );
    plcol0( 1 );
    pllab( "X Coordinate", "Y Coordinate", "Streamlines of flow" );
    //
    // pl_setcontlabelparam(0.006, 0.3, 0.1, 1);
    // plenv(-1.0, 1.0, -1.0, 1.0, 0, 0);
    // plcol0(2);
    // plcont((const PLFLT **) z, XPTS, YPTS, 1, XPTS, 1, YPTS, clevel, 11,
    //     pltr1, (void *) &cgrid1);
    //
    // plstyl(1, &mark, &space);
    // plcol0(3);
    // plcont((const PLFLT **) w, XPTS, YPTS, 1, XPTS, 1, YPTS, clevel, 11,
    //     pltr1, (void *) &cgrid1);
    // plstyl(0, &mark, &space);
    // plcol0(1);
    // pllab("X Coordinate", "Y Coordinate", "Streamlines of flow");
    // pl_setcontlabelparam(0.006, 0.3, 0.1, 0);
    //
// Plot using 2d coordinate transform

    plenv( -1.0, 1.0, -1.0, 1.0, 0, 0 );
    plcol0( 2 );
    plcont( (const PLFLT * const *) z, XPTS, YPTS, 1, XPTS, 1, YPTS, clevel, 11,
        pltr2, (void *) &cgrid2 );

    plstyl( 1, &mark, &space );
    plcol0( 3 );
    plcont( (const PLFLT * const *) w, XPTS, YPTS, 1, XPTS, 1, YPTS, clevel, 11,
        pltr2, (void *) &cgrid2 );
    plstyl( 0, &mark, &space );
    plcol0( 1 );
    pllab( "X Coordinate", "Y Coordinate", "Streamlines of flow" );
    //
    // pl_setcontlabelparam(0.006, 0.3, 0.1, 1);
    // plenv(-1.0, 1.0, -1.0, 1.0, 0, 0);
    // plcol0(2);
    // plcont((const PLFLT **) z, XPTS, YPTS, 1, XPTS, 1, YPTS, clevel, 11,
    //     pltr2, (void *) &cgrid2);
    //
    // plstyl(1, &mark, &space);
    // plcol0(3);
    // plcont((const PLFLT **) w, XPTS, YPTS, 1, XPTS, 1, YPTS, clevel, 11,
    //     pltr2, (void *) &cgrid2);
    // plstyl(0, &mark, &space);
    // plcol0(1);
    // pllab("X Coordinate", "Y Coordinate", "Streamlines of flow");
    //
    pl_setcontlabelparam( 0.006, 0.3, 0.1, 0 );
    polar();
    //
    // pl_setcontlabelparam(0.006, 0.3, 0.1, 1);
    // polar();
    //
    pl_setcontlabelparam( 0.006, 0.3, 0.1, 0 );
    potential();
    //
    // pl_setcontlabelparam(0.006, 0.3, 0.1, 1);
    // potential();
    //

// Clean up

    plFree2dGrid( z, XPTS, YPTS );
    plFree2dGrid( w, XPTS, YPTS );
    plFree2dGrid( cgrid2.xg, XPTS, YPTS );
    plFree2dGrid( cgrid2.yg, XPTS, YPTS );

    plend();

    exit( 0 );
}
Example #18
0
static void plplot_set_labels( plot_driver_type * driver , const char * title , const char * xlabel , const char * ylabel , plot_color_type label_color , double label_font_size) {
  plcol0(label_color);
  plschr(0, label_font_size * PLOT_DEFAULT_LABEL_FONTSIZE);
  pllab(xlabel, ylabel, title);
}
Example #19
0
void
shade(void)
{
    int i, j;
    PLFLT x, y, argx, argy, distort;

    PLFLT **z, **w, zmin, zmax;
    PLFLT xg1[XPTS], yg1[YPTS];
    PLcGrid  cgrid1;
    PLcGrid2 cgrid2;

    PLFLT shade_min, shade_max, sh_color;
    PLINT sh_cmap = 1, sh_width;
    PLINT min_color = 1, min_width = 0, max_color = 0, max_width = 0;

/* Set up function arrays */

    plAlloc2dGrid(&z, XPTS, YPTS);
    plAlloc2dGrid(&w, XPTS, YPTS);

/* Set up data array */

    for (i = 0; i < XPTS; i++) {
	x = (double) (i - (XPTS / 2)) / (double) (XPTS / 2);
	for (j = 0; j < YPTS; j++) {
	    y = (double) (j - (YPTS / 2)) / (double) (YPTS / 2) - 1.0;

	    z[i][j] = - sin(7.*x) * cos(7.*y) + x*x - y*y;
	    w[i][j] = - cos(7.*x) * sin(7.*y) + 2 * x * y;
	}
    }
    f2mnmx(z, XPTS, YPTS, &zmin, &zmax);
    for (i = 0; i < NCONTR; i++)
	clevel[i] = zmin + (zmax - zmin) * (i + 0.5) / (PLFLT) NCONTR;

/* Set up coordinate grids */

    cgrid1.xg = xg1;
    cgrid1.yg = yg1;
    cgrid1.nx = XPTS;
    cgrid1.ny = YPTS;

    plAlloc2dGrid(&cgrid2.xg, XPTS, YPTS);
    plAlloc2dGrid(&cgrid2.yg, XPTS, YPTS);
    cgrid2.nx = XPTS;
    cgrid2.ny = YPTS;

    for (i = 0; i < XPTS; i++) {
	for (j = 0; j < YPTS; j++) {
	    mypltr((PLFLT) i, (PLFLT) j, &x, &y, NULL);

	    argx = x * PI/2;
	    argy = y * PI/2;
	    distort = 0.4;

	    cgrid1.xg[i] = x + distort * cos(argx);
	    cgrid1.yg[j] = y - distort * cos(argy);

	    cgrid2.xg[i][j] = x + distort * cos(argx) * cos(argy);
	    cgrid2.yg[i][j] = y - distort * cos(argx) * cos(argy);
	}
    }

/* Plot using identity transform */

    pladv(0);
    plvpor(0.1, 0.9, 0.1, 0.9);
    plwind(-1.0, 1.0, -1.0, 1.0);

    for (i = 0; i < NCONTR; i++) {
	shade_min = zmin + (zmax - zmin) * i / (PLFLT) NCONTR;
	shade_max = zmin + (zmax - zmin) * (i +1) / (PLFLT) NCONTR;
	sh_color = i / (PLFLT) (NCONTR-1);
	sh_width = 2;
	plpsty(0);

	plshade(z, XPTS, YPTS, NULL, -1., 1., -1., 1.,
		shade_min, shade_max,
		sh_cmap, sh_color, sh_width,
		min_color, min_width, max_color, max_width,
		plfill, 1, NULL, NULL);
    }

    plcol(1);
    plbox("bcnst", 0.0, 0, "bcnstv", 0.0, 0);
    plcol(2);
/*
    plcont(w, XPTS, YPTS, 1, XPTS, 1, YPTS, clevel, NCONTR, mypltr, NULL);
    */
    pllab("distance", "altitude", "Bogon density");

/* Clean up */

    plFree2dGrid(z, XPTS, YPTS);
    plFree2dGrid(w, XPTS, YPTS);
    plFree2dGrid(cgrid2.xg, XPTS, YPTS);
    plFree2dGrid(cgrid2.yg, XPTS, YPTS);
}
/*
 * Plot specified x/y coordinates, x as int32_t and y as float, with an arbitrary number
 * of separate lines, as lines and/or points.
 * Output is PDF file, location specified by 'fileName'.
 */
int plplotLines(
    PlplotSetup *setup,
    uint32_t numSamples,	/* size of ix[] and fy[] arrays */
    uint32_t numLines,		/* size of lineDef[] array */
    int32_t *ix,			/* numSamples */
    LineDef *lineDef,		/* numLines */
    const char *graphName,
    const char *fileName,
    bool plotPoints,		/* true: plot points */
    bool plotLine,			/* true: plot line */
    bool skipTrailZeroes)	/* don't plot zero Y values at end of graph */
{
    if(setup == NULL) {
        printf("***plplotLine: setup required\n");
        return -1;
    }

    char tmpFile[TEMP_FN_LEN];
    makeTempFile(tmpFile, TEMP_FN_LEN);

    PLFLT fx[numSamples];
    PLFLT minX = setup->minX;
    PLFLT maxX = setup->maxX;
    PLFLT minY = setup->minY;
    PLFLT maxY = setup->maxY;

    for(uint32_t dex=0; dex<numSamples; dex++) {
        fx[dex] = ix[dex];
    }

    const char *yName = "";
    if(setup->yAxisName) {
        yName = setup->yAxisName;
    }
    const char *xName = "";
    if(setup->xAxisName) {
        xName = setup->xAxisName;
    }

    plsdev ("psc");

    /* standard: background white, foreground (axes, labels, etc.) black */
    plscolbg(PLOT_WHITE);
    plscol0(1, PLOT_BLACK);

    plsfnam(tmpFile);
    plsdiori(1.0);						// portrait
    plinit();
    plenv(minX, maxX, minY, maxY, 0, 0);
    pllab(xName, yName, graphName);

    for(uint32_t dex=0; dex<numLines; dex++) {
        uint32_t thisSamples = numSamples;
        if(skipTrailZeroes) {
            while((lineDef[dex].fy[thisSamples-1] == 0.0) && (thisSamples > 0)) {
                thisSamples--;
            }
            if(thisSamples == 0) {
                printf("***plplotLines: Warning: line with all zeroes skipped\n");
                continue;
            }
        }
        plotOneLine(thisSamples, fx,  &lineDef[dex], plotPoints, plotLine);
    }

    plend();

    int ourRtn = psToPdf(tmpFile, fileName);
    unlink(tmpFile);
    return ourRtn;
}
Example #21
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
    }
}
/*
 * Plot a histogram of prebinned data. X values are int32_t's, and the corresponding
 * Y values - the counts for each X - are uint32_t's.
 */
int plplotBins(
    uint32_t numBins,
    const int32_t *x,			/* numBins of X values, monotonically increasing */
    const uint32_t *y,			/* numBins of Y values for each associated X */
    const char *graphName,
    const char *fileName,
    const char *xAxisName,		/* optional */
    const char *yAxisName)		/* optional */
{
    char tmpFile[TEMP_FN_LEN];
    makeTempFile(tmpFile, TEMP_FN_LEN);

    PLINT totalBins = numBins + 2;

    /* PLFLT array of sample values */
    PLFLT *xf = (PLFLT *)malloc(totalBins * sizeof(PLFLT));

    /* these two will have Y values of zero */
    xf[0] = x[0] - 1;
    xf[totalBins - 1] = x[numBins-1] + 1;

    const int32_t *ip = x;
    PLFLT *op = xf + 1;
    for(uint32_t dex=0; dex<numBins; dex++) {
        *op++ = *ip++;
    }

    /* PLFLT array of bins */
    PLFLT *yf = (PLFLT *)malloc(totalBins * sizeof(PLFLT));
    yf[0] = 0.0;
    yf[totalBins - 1]  = 0.0;
    const uint32_t *uip = y;
    op = yf + 1;
    for(uint32_t dex=0; dex<numBins; dex++) {
        *op++ = *uip++;
    }

    /* get max Y value */
    uint32_t maxY = 0;
    uip = y;
    for(uint32_t dex=0; dex<numBins; dex++) {
        uint32_t currY = *uip++;
        if(currY > maxY) {
            maxY = currY;
        }
    }

    const char *yName = yAxisName ? yAxisName : "";
    const char *xName = xAxisName ? xAxisName : "";

#if	HIST_COLOR
    plsdev ("psc");
    plscolbg(255, 255, 255);			/* white background */
#else
    plsdev ("ps");
#endif
    plsfnam(tmpFile);
    plsdiori(1.0);						// portrait
    plinit();
    plenv(xf[0], xf[totalBins - 1], 0, maxY, 0, 0);

#if	HIST_COLOR
    /* can we alter colors of lines and the spaces inside the histograms? */
    plscolbg(255, 0, 0);				/* red background */
    plscol0(1, 255, 0, 0);				/* red foreground - no effect */
#endif

    pllab(xName, yName, graphName);

    plbin(totalBins, xf, yf, PL_BIN_CENTRED);
    plend();

    free(xf);
    free(yf);

    int ourRtn = psToPdf(tmpFile, fileName);
    unlink(tmpFile);
    return ourRtn;
}
/*
 * Plot a histogram showing the number of occurences of each possible
 * value of 'samples'.
 */
int plplotHist(
    const int32_t *samples,
    uint32_t numSamples,
    const char *graphName,
    const char *fileName,
    const char *xAxisName,		/* optional */
    const char *yAxisName)		/* optional */
{
    char tmpFile[TEMP_FN_LEN];
    makeTempFile(tmpFile, TEMP_FN_LEN);

    /* First determine the range, i.e. the number of bins */
    int32_t minSamp = samples[0];
    int32_t maxSamp = samples[0];
    for(uint32_t dex=0; dex<numSamples; dex++) {
        int32_t s = samples[dex];
        if(s < minSamp) {
            minSamp = s;
        }
        if(s > maxSamp) {
            maxSamp = s;
        }
    }

    /* When we specify PL_BIN_CENTRED, the min and max values are half the normal width */
    minSamp--;
    maxSamp++;

    PLINT numBins = maxSamp - minSamp + 1;

    /* One array containing the sample values, x */
    PLFLT *x = (PLFLT *)malloc(numBins * sizeof(PLFLT));
    int32_t binNum = minSamp;
    for(uint32_t dex=0; dex<(uint32_t)numBins; dex++) {
        x[dex] = binNum++;
    }

    /* Now make and fill the bins proper */
    PLFLT *y = (PLFLT *)malloc(numBins * sizeof(PLFLT));
    for(uint32_t dex=0; dex<(uint32_t)numBins; dex++) {
        y[dex] = 0;
    }
    PLFLT maxY = 0.0;

    for(uint32_t dex=0; dex<numSamples; dex++) {
        int32_t s = samples[dex];
        PLFLT *yp = y + s - minSamp;
        *yp += 1.0;
        if(*yp > maxY) {
            maxY = *yp;
        }
    }

    const char *yName = yAxisName ? yAxisName : "";
    const char *xName = xAxisName ? xAxisName : "";

#if	HIST_COLOR
    plsdev ("psc");
    plscolor(1);
    plscolbg(255, 255, 255);			/* white background */
#else
    plsdev ("ps");
#endif
    plsfnam(tmpFile);
    plsdiori(1.0);						// portrait
    plinit();
    plenv(minSamp, maxSamp, 0, maxY, 0, 0);

#if	HIST_COLOR
    /* can we alter colors of lines and the spaces inside the histograms? */
    plscolbg(255, 0, 0);				/* red background */
    plscol0(1, 255, 0, 0);				/* red foreground - no effect */
#endif

    pllab(xName, yName, graphName);

    plbin(numBins, x, y, PL_BIN_CENTRED);
    plend();

    free(x);
    free(y);

    int ourRtn = psToPdf(tmpFile, fileName);
    unlink(tmpFile);
    return ourRtn;
}
Example #24
0
int
main(int argc, char *argv[])
{
  PLFLT *x, *y, *z, *clev;
  PLFLT *xg, *yg, **zg, **szg;
  PLFLT zmin, zmax, lzm, lzM;
  long ct;
  int i, j, k;
  PLINT alg;
  char ylab[40], xlab[40];
  char *title[] = {"Cubic Spline Approximation",
		   "Delaunay Linear Interpolation",
		   "Natural Neighbors Interpolation",
		   "KNN Inv. Distance Weighted",
		   "3NN Linear Interpolation",
		   "4NN Around Inv. Dist. Weighted"};

  PLFLT opt[] = {0., 0., 0., 0., 0., 0.};

  xm = ym = -0.2;
  xM = yM = 0.8;

  plMergeOpts(options, "x21c options", NULL);
  plparseopts(&argc, argv, PL_PARSE_FULL);

  opt[2] = wmin;
  opt[3] = (PLFLT) knn_order;
  opt[4] = threshold;

  /* Initialize plplot */

  plinit();

  create_data(&x, &y, &z, pts); /* the sampled data */
  zmin = z[0];
  zmax = z[0];
  for (i=1; i<pts; i++) {
    if (z[i] > zmax)
      zmax = z[i];
    if (z[i] < zmin)
      zmin = z[i];
  }

  create_grid(&xg, xp, &yg, yp); /* grid the data at */
  plAlloc2dGrid(&zg, xp, yp); /* the output grided data */
  clev = (PLFLT *) malloc(nl * sizeof(PLFLT));

  sprintf(xlab, "Npts=%d gridx=%d gridy=%d", pts, xp, yp);
  plcol0(1);
  plenv(xm, xM, ym, yM, 2, 0);
  plcol0(15);
  pllab(xlab, "", "The original data");
  plcol0(2);
  plpoin(pts, x, y, 5);
  pladv(0);

  plssub(3,2);

  for (k=0; k<2; k++) {
    pladv(0);
    for (alg=1; alg<7; alg++) {

      ct = clock();
      plgriddata(x, y, z, pts, xg, xp, yg, yp, zg, alg, opt[alg-1]);
      sprintf(xlab, "time=%d ms", (clock() - ct)/1000);
      sprintf(ylab, "opt=%.3f", opt[alg-1]);

      /* - CSA can generate NaNs (only interpolates?!).
       * - DTLI and NNI can generate NaNs for points outside the convex hull
       *      of the data points.
       * - NNLI can generate NaNs if a sufficiently thick triangle is not found
       *
       * PLplot should be NaN/Inf aware, but changing it now is quite a job...
       * so, instead of not plotting the NaN regions, a weighted average over
       * the neighbors is done.
       */

      if (alg == GRID_CSA || alg == GRID_DTLI || alg == GRID_NNLI || alg == GRID_NNI) {
	int ii, jj;
	PLFLT dist, d;

	for (i=0; i<xp; i++) {
	  for (j=0; j<yp; j++) {
	    if (isnan(zg[i][j])) { /* average (IDW) over the 8 neighbors */

	      zg[i][j] = 0.; dist = 0.;

	      for (ii=i-1; ii<=i+1 && ii<xp; ii++) {
		for (jj=j-1; jj<=j+1 && jj<yp; jj++) {
		  if (ii >= 0 && jj >= 0 && !isnan(zg[ii][jj])) {
		    d = (abs(ii-i) + abs(jj-j)) == 1 ? 1. : 1.4142;
		    zg[i][j] += zg[ii][jj]/(d*d);
		    dist += d;
		  }
		}
	      }
	      if (dist != 0.)
		zg[i][j] /= dist;
	      else
		zg[i][j] = zmin;

	    }
	  }
	}
      }

      plMinMax2dGrid(zg, xp, yp, &lzM, &lzm);

      plcol0(1);
      pladv(alg);

      if (k == 0) {

	lzm = MIN(lzm, zmin);
	lzM = MAX(lzM, zmax);
	for (i=0; i<nl; i++)
	  clev[i] = lzm + (lzM-lzm)/(nl-1)*i;

	plenv0(xm, xM, ym, yM, 2, 0);
	plcol0(15);
	pllab(xlab, ylab, title[alg-1]);
	plshades(zg, xp, yp, NULL, xm, xM, ym, yM,
		 clev, nl, 1, 0, 1, plfill, 1, NULL, NULL);
	plcol0(2);
      } else {

	for (i=0; i<nl; i++)
	  clev[i] = lzm + (lzM-lzm)/(nl-1)*i;

	cmap1_init();
	plvpor(0.0, 1.0, 0.0, 0.9);
	plwind(-1.0, 1.0, -1.0, 1.5);
	/*
	 * For the comparition to be fair, all plots should have the
	 * same z values, but to get the max/min of the data generated
	 * by all algorithms would imply two passes. Keep it simple.
	 *
	 * plw3d(1., 1., 1., xm, xM, ym, yM, zmin, zmax, 30, -60);
	 */

	plw3d(1., 1., 1., xm, xM, ym, yM, lzm, lzM, 30, -60);
	plbox3("bnstu", ylab, 0.0, 0,
	       "bnstu", xlab, 0.0, 0,
	       "bcdmnstuv", "", 0.0, 4);
	plcol0(15);
	pllab("", "", title[alg-1]);
	plot3dc(xg, yg, zg, xp, yp, DRAW_LINEXY | MAG_COLOR | BASE_CONT, clev, nl);
      }
    }
  }

  plend();

  free_data(x, y, z);
  free_grid(xg, yg);
  free((void *)clev);
  plFree2dGrid(zg, xp, yp);
}
Example #25
0
int
main( int argc, char **argv )
{
    PLFLT       minx, maxx, miny, maxy;
    PLFLT       x, y;
    //variables for the shapelib example
    const PLINT nbeachareas    = 2;
    const PLINT beachareas[]   = { 23, 24 };
    const PLINT nwoodlandareas = 94;
    PLINT       woodlandareas[94];
    const PLINT nshingleareas  = 22;
    const PLINT shingleareas[] = { 0, 1, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 217, 2424, 2425, 2426, 2427, 2428, 2491, 2577 };
    const PLINT ncragareas     = 2024;
    PLINT       cragareas[2024];
    const PLINT majorroads[] = { 33, 48, 71, 83, 89, 90, 101, 102, 111 };
    int         i;

// Parse and process command line arguments

    (void) plparseopts( &argc, argv, PL_PARSE_FULL );

// Longitude (x) and latitude (y)

    miny = -70;
    maxy = 80;

    plinit();

// Cartesian plots
// Most of world

    minx = -170;
    maxx = minx + 360;

    // Setup a custom latitude and longitude-based scaling function.
    plslabelfunc( geolocation_labeler, NULL );

    plcol0( 1 );
    plenv( minx, maxx, miny, maxy, 1, 70 );
    plmap( NULL, "usaglobe", minx, maxx, miny, maxy );

// The Americas

    minx = 190;
    maxx = 340;

    plcol0( 1 );
    plenv( minx, maxx, miny, maxy, 1, 70 );
    plmap( NULL, "usaglobe", minx, maxx, miny, maxy );

    // Clear the labeling function
    plslabelfunc( NULL, NULL );

// Polar, Northern hemisphere

    minx = 0;
    maxx = 360;

    plenv( -75., 75., -75., 75., 1, -1 );
    plmap( mapform19, "globe", minx, maxx, miny, maxy );

    pllsty( 2 );
    plmeridians( mapform19, 10.0, 10.0, 0.0, 360.0, -10.0, 80.0 );

// Polar, Northern hemisphere, this time with a PLplot-wide transform

    minx = 0;
    maxx = 360;

    plstransform( map_transform, NULL );

    pllsty( 1 );
    plenv( -75., 75., -75., 75., 1, -1 );
    // No need to set the map transform here as the global transform will be
    // used.
    plmap( NULL, "globe", minx, maxx, miny, maxy );

    pllsty( 2 );
    plmeridians( NULL, 10.0, 10.0, 0.0, 360.0, -10.0, 80.0 );

    // Show Baltimore, MD on the map
    plcol0( 2 );
    plssym( 0.0, 2.0 );
    x = -76.6125;
    y = 39.2902778;
    plpoin( 1, &x, &y, 18 );
    plssym( 0.0, 1.0 );
    plptex( -76.6125, 43.0, 0.0, 0.0, 0.0, "Baltimore, MD" );

    // For C, this is how the global transform is cleared
    plstransform( NULL, NULL );

    // An example using shapefiles. The shapefiles used are from Ordnance Survey, UK.
    // These were chosen because they provide shapefiles for small grid boxes which
    // are easilly manageable for this demo.

    pllsty( 1 );


    minx = 240570;
    maxx = 621109;
    miny = 87822;
    maxy = 722770;
    plscol0( 0, 255, 255, 255 );
    plscol0( 1, 0, 0, 0 );
    plscol0( 2, 150, 150, 150 );
    plscol0( 3, 0, 50, 200 );
    plscol0( 4, 50, 50, 50 );
    plscol0( 5, 150, 0, 0 );
    plscol0( 6, 100, 100, 255 );


    minx = 265000;
    maxx = 270000;
    miny = 145000;
    maxy = 150000;
    plscol0( 0, 255, 255, 255 ); //white
    plscol0( 1, 0, 0, 0 );       //black
    plscol0( 2, 255, 200, 0 );   //yelow for sand
    plscol0( 3, 60, 230, 60 );   // green for woodland
    plscol0( 4, 210, 120, 60 );  //brown for contours
    plscol0( 5, 150, 0, 0 );     //red for major roads
    plscol0( 6, 180, 180, 255 ); //pale blue for water
    plscol0( 7, 100, 100, 100 ); //pale grey for shingle or boulders
    plscol0( 8, 100, 100, 100 ); //dark grey for custom polygons - generally crags


    plcol0( 1 );
    plenv( minx, maxx, miny, maxy, 1, -1 );
    pllab( "", "", "Martinhoe CP, Exmoor National Park, UK (shapelib only)" );


    //Beach
    plcol0( 2 );
    plmapfill( NULL, "ss/ss64ne_Landform_Area", minx, maxx, miny, maxy, beachareas, nbeachareas );

    //woodland
    plcol0( 3 );
    for ( i = 0; i < nwoodlandareas; ++i )
        woodlandareas[i] = i + 218;
    plmapfill( NULL, "ss/ss64ne_Landform_Area", minx, maxx, miny, maxy, (PLINT_VECTOR) woodlandareas, nwoodlandareas );

    //shingle or boulders
    plcol0( 7 );
    plmapfill( NULL, "ss/ss64ne_Landform_Area", minx, maxx, miny, maxy, shingleareas, nshingleareas );

    //crags
    plcol0( 8 );
    for ( i = 0; i < ncragareas; ++i )
        cragareas[i] = i + 325;
    plmapfill( NULL, "ss/ss64ne_Landform_Area", minx, maxx, miny, maxy, (PLINT_VECTOR) cragareas, ncragareas );

    //draw contours, we need to separate contours from high/low coastline
    //draw_contours(pls, "ss/SS64_line", 433, 20, 4, 3, minx, maxx, miny, maxy );
    plcol0( 4 );
    plmapline( NULL, "ss/ss64ne_Height_Contours", minx, maxx, miny, maxy, NULL, 0 );

    //draw the sea and surface water
    plwidth( 0.0 );
    plcol0( 6 );
    plmapfill( NULL, "ss/ss64ne_Water_Area", minx, maxx, miny, maxy, NULL, 0 );
    plwidth( 2.0 );
    plmapfill( NULL, "ss/ss64ne_Water_Line", minx, maxx, miny, maxy, NULL, 0 );

    //draw the roads, first with black and then thinner with colour to give an
    //an outlined appearance
    plwidth( 5.0 );
    plcol0( 1 );
    plmapline( NULL, "ss/ss64ne_Road_Centreline", minx, maxx, miny, maxy, NULL, 0 );
    plwidth( 3.0 );
    plcol0( 0 );
    plmapline( NULL, "ss/ss64ne_Road_Centreline", minx, maxx, miny, maxy, NULL, 0 );
    plcol0( 5 );
    plmapline( NULL, "ss/ss64ne_Road_Centreline", minx, maxx, miny, maxy, majorroads, 9 );

    //draw buildings
    plwidth( 1.0 );
    plcol0( 1 );
    plmapfill( NULL, "ss/ss64ne_Building_Area", minx, maxx, miny, maxy, NULL, 0 );

    //labels
    plsfci( 0x80000100 );
    plschr( 0, 0.8 );
    plmaptex( NULL, "ss/ss64ne_General_Text", 1.0, 0.0, 0.5, "MARTINHOE CP", minx, maxx, miny, maxy, 202 );
    plschr( 0, 0.7 );
    plmaptex( NULL, "ss/ss64ne_General_Text", 1.0, 0.0, 0.5, "Heale\nDown", minx, maxx, miny, maxy, 13 );
    plmaptex( NULL, "ss/ss64ne_General_Text", 1.0, 0.0, 0.5, "South\nDown", minx, maxx, miny, maxy, 34 );
    plmaptex( NULL, "ss/ss64ne_General_Text", 1.0, 0.0, 0.5, "Martinhoe\nCommon", minx, maxx, miny, maxy, 42 );
    plmaptex( NULL, "ss/ss64ne_General_Text", 1.0, 0.0, 0.5, "Woody Bay", minx, maxx, miny, maxy, 211 );
    plschr( 0, 0.6 );
    plmaptex( NULL, "ss/ss64ne_General_Text", 1.0, 0.0, 0.5, "Mill Wood", minx, maxx, miny, maxy, 16 );
    plmaptex( NULL, "ss/ss64ne_General_Text", 1.0, 0.0, 0.5, "Heale Wood", minx, maxx, miny, maxy, 17 );
    plmaptex( NULL, "ss/ss64ne_General_Text", 1.0, 0.0, 1.0, "Bodley", minx, maxx, miny, maxy, 31 );
    plmaptex( NULL, "ss/ss64ne_General_Text", 1.0, 0.0, 0.0, "Martinhoe", minx, maxx, miny, maxy, 37 );
    plmaptex( NULL, "ss/ss64ne_General_Text", 1.0, 0.0, 0.5, "Woolhanger\nCommon", minx, maxx, miny, maxy, 60 );
    plmaptex( NULL, "ss/ss64ne_General_Text", 1.0, 0.0, 0.5, "West Ilkerton\nCommon", minx, maxx, miny, maxy, 61 );
    plmaptex( NULL, "ss/ss64ne_General_Text", 1.0, 0.0, 0.5, "Caffyns\nHeanton\nDown", minx, maxx, miny, maxy, 62 );

    plend();
    exit( 0 );
}
Example #26
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
}
Example #27
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);
}
Example #28
0
File: plp.c Project: a4a881d4/aloe
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

}