Ejemplo n.º 1
0
int
main(int argc, char *argv[])
{
    char text[10];
    int i, j, k;
    PLFLT x, y;

/* Parse and process command line arguments */

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

/* Initialize plplot */

    plinit();

    pladv(0);

/* Set up viewport and window */

    plcol0(2);
    plvpor(0.1, 1.0, 0.1, 0.9);
    plwind(0.0, 1.0, 0.0, 1.3);

/* Draw the grid using plbox */

    plbox("bcg", 0.1, 0, "bcg", 0.1, 0);

/* Write the digits below the frame */

    plcol0(15);
    for (i = 0; i <= 9; i++) {
	sprintf(text, "%d", i);
	plmtex("b", 1.5, (0.1 * i + 0.05), 0.5, text);
    }

    k = 0;
    for (i = 0; i <= 12; i++) {

    /* Write the digits to the left of the frame */

	sprintf(text, "%d", 10 * i);
	plmtex("lv", 1.0, (1.0 - (2 * i + 1) / 26.0), 1.0, text);
	for (j = 0; j <= 9; j++) {
	    x = 0.1 * j + 0.05;
	    y = 1.25 - 0.1 * i;

	/* Display the symbols (plpoin expects that x and y are arrays so */
	/* pass pointers) */

	    if (k < 128)
		plpoin(1, &x, &y, k);
	    k = k + 1;
	}
    }

    plmtex("t", 1.5, 0.5, 0.5, "PLplot Example 6 - plpoin symbols");
    plend();
    exit(0);
}
Ejemplo n.º 2
0
void
c_pllab(const char *xlabel, const char *ylabel, const char *tlabel)
{
    if (plsc->level < 2) {
	plabort("pllab: Please set up viewport first");
	return;
    }

    plmtex("t", (PLFLT) 2.0, (PLFLT) 0.5, (PLFLT) 0.5, tlabel);
    plmtex("b", (PLFLT) 3.2, (PLFLT) 0.5, (PLFLT) 0.5, xlabel);
    plmtex("l", (PLFLT) 5.0, (PLFLT) 0.5, (PLFLT) 0.5, ylabel);
}
Ejemplo n.º 3
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);
}
Ejemplo n.º 4
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;
}
Ejemplo n.º 5
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;
}
Ejemplo n.º 6
0
int
main( int argc, const char *argv[] )
{
    int      i, j, k;
    PLFLT    *x, *y, **z, *z_row_major, *z_col_major;
    PLFLT    dx = 2. / (PLFLT) ( XPTS - 1 );
    PLFLT    dy = 2. / (PLFLT) ( YPTS - 1 );
    PLfGrid2 grid_c, grid_row_major, grid_col_major;
    PLFLT    xx, yy, r;
    PLINT    ifshade;
    PLFLT    zmin, zmax, step;
    PLFLT    clevel[LEVELS];
    PLINT    nlevel = LEVELS;

    PLINT    indexxmin = 0;
    PLINT    indexxmax = XPTS;
    PLINT    *indexymin;
    PLINT    *indexymax;
    PLFLT    **zlimited;
    // parameters of ellipse (in x, y index coordinates) that limits the data.
    // x0, y0 correspond to the exact floating point centre of the index
    // range.
    PLFLT x0 = 0.5 * (PLFLT) ( XPTS - 1 );
    PLFLT a  = 0.9 * x0;
    PLFLT y0 = 0.5 * (PLFLT) ( YPTS - 1 );
    PLFLT b  = 0.7 * y0;
    PLFLT square_root;

    // Parse and process command line arguments
    plMergeOpts( options, "x08c options", NULL );
    (void) plparseopts( &argc, argv, PL_PARSE_FULL );

    // Initialize plplot

    plinit();

// Allocate data structures

    x = (PLFLT *) calloc( XPTS, sizeof ( PLFLT ) );
    y = (PLFLT *) calloc( YPTS, sizeof ( PLFLT ) );

    plAlloc2dGrid( &z, XPTS, YPTS );
    z_row_major = (PLFLT *) malloc( XPTS * YPTS * sizeof ( PLFLT ) );
    z_col_major = (PLFLT *) malloc( XPTS * YPTS * sizeof ( PLFLT ) );
    if ( !z_row_major || !z_col_major )
        plexit( "Memory allocation error" );

    grid_c.f         = z;
    grid_row_major.f = (PLFLT **) z_row_major;
    grid_col_major.f = (PLFLT **) z_col_major;
    grid_c.nx        = grid_row_major.nx = grid_col_major.nx = XPTS;
    grid_c.ny        = grid_row_major.ny = grid_col_major.ny = YPTS;

    for ( i = 0; i < XPTS; i++ )
    {
        x[i] = -1. + (PLFLT) i * dx;
        if ( rosen )
            x[i] *= 1.5;
    }

    for ( j = 0; j < YPTS; j++ )
    {
        y[j] = -1. + (PLFLT) j * dy;
        if ( rosen )
            y[j] += 0.5;
    }

    for ( i = 0; i < XPTS; i++ )
    {
        xx = x[i];
        for ( j = 0; j < YPTS; j++ )
        {
            yy = y[j];
            if ( rosen )
            {
                z[i][j] = pow( 1. - xx, 2. ) + 100. * pow( yy - pow( xx, 2. ), 2. );

                // The log argument might be zero for just the right grid.
                if ( z[i][j] > 0. )
                    z[i][j] = log( z[i][j] );
                else
                    z[i][j] = -5.; // -MAXFLOAT would mess-up up the scale
            }
            else
            {
                r       = sqrt( xx * xx + yy * yy );
                z[i][j] = exp( -r * r ) * cos( 2.0 * M_PI * r );
            }

            z_row_major[i * YPTS + j] = z[i][j];
            z_col_major[i + XPTS * j] = z[i][j];
        }
    }

    // Allocate and calculate y index ranges and corresponding zlimited.
    plAlloc2dGrid( &zlimited, XPTS, YPTS );
    indexymin = (PLINT *) malloc( XPTS * sizeof ( PLINT ) );
    indexymax = (PLINT *) malloc( XPTS * sizeof ( PLINT ) );
    if ( !indexymin || !indexymax )
        plexit( "Memory allocation error" );

    //printf("XPTS = %d\n", XPTS);
    //printf("x0 = %f\n", x0);
    //printf("a = %f\n", a);
    //printf("YPTS = %d\n", YPTS);
    //printf("y0 = %f\n", y0);
    //printf("b = %f\n", b);

    // These values should all be ignored because of the i index range.
#if 0
    for ( i = 0; i < indexxmin; i++ )
    {
        indexymin[i] = 0;
        indexymax[i] = YPTS;
        for ( j = indexymin[i]; j < indexymax[i]; j++ )
            // Mark with large value to check this is ignored.
            zlimited[i][j] = 1.e300;
    }
#endif
    for ( i = indexxmin; i < indexxmax; i++ )
    {
        square_root = sqrt( 1. - MIN( 1., pow( ( (PLFLT) i - x0 ) / a, 2. ) ) );
        // Add 0.5 to find nearest integer and therefore preserve symmetry
        // with regard to lower and upper bound of y range.
        indexymin[i] = MAX( 0, (PLINT) ( 0.5 + y0 - b * square_root ) );
        // indexymax calculated with the convention that it is 1
        // greater than highest valid index.
        indexymax[i] = MIN( YPTS, 1 + (PLINT) ( 0.5 + y0 + b * square_root ) );
        //printf("i, b*square_root, indexymin[i], YPTS - indexymax[i] = %d, %e, %d, %d\n", i, b*square_root, indexymin[i], YPTS - indexymax[i]);

#if 0
        // These values should all be ignored because of the j index range.
        for ( j = 0; j < indexymin[i]; j++ )
            // Mark with large value to check this is ignored.
            zlimited[i][j] = 1.e300;
#endif

        for ( j = indexymin[i]; j < indexymax[i]; j++ )
            zlimited[i][j] = z[i][j];

#if 0
        // These values should all be ignored because of the j index range.
        for ( j = indexymax[i]; j < YPTS; j++ )
            // Mark with large value to check this is ignored.
            zlimited[i][j] = 1.e300;
#endif
    }

#if 0
    // These values should all be ignored because of the i index range.
    for ( i = indexxmax; i < XPTS; i++ )
    {
        indexymin[i] = 0;
        indexymax[i] = YPTS;
        for ( j = indexymin[i]; j < indexymax[i]; j++ )
            // Mark with large value to check this is ignored.
            zlimited[i][j] = 1.e300;
    }
#endif

    plMinMax2dGrid( (const PLFLT * const *) z, XPTS, YPTS, &zmax, &zmin );
    step = ( zmax - zmin ) / ( nlevel + 1 );
    for ( i = 0; i < nlevel; i++ )
        clevel[i] = zmin + step + step * i;

    pllightsource( 1., 1., 1. );

    for ( k = 0; k < 2; k++ )
    {
        for ( ifshade = 0; ifshade < 5; ifshade++ )
        {
            pladv( 0 );
            plvpor( 0.0, 1.0, 0.0, 0.9 );
            plwind( -1.0, 1.0, -0.9, 1.1 );
            plcol0( 3 );
            plmtex( "t", 1.0, 0.5, 0.5, title[k] );
            plcol0( 1 );
            if ( rosen )
                plw3d( 1.0, 1.0, 1.0, -1.5, 1.5, -0.5, 1.5, zmin, zmax, alt[k], az[k] );
            else
                plw3d( 1.0, 1.0, 1.0, -1.0, 1.0, -1.0, 1.0, zmin, zmax, alt[k], az[k] );

            plbox3( "bnstu", "x axis", 0.0, 0,
                "bnstu", "y axis", 0.0, 0,
                "bcdmnstuv", "z axis", 0.0, 0 );
            plcol0( 2 );

            if ( ifshade == 0 ) // diffuse light surface plot
            {
                cmap1_init( 1 );
                plfsurf3d( x, y, plf2ops_c(), (PLPointer) z, XPTS, YPTS, 0, NULL, 0 );
            }
            else if ( ifshade == 1 ) // magnitude colored plot
            {
                cmap1_init( 0 );
                plfsurf3d( x, y, plf2ops_grid_c(), ( PLPointer ) & grid_c, XPTS, YPTS, MAG_COLOR, NULL, 0 );
            }
            else if ( ifshade == 2 ) //  magnitude colored plot with faceted squares
            {
                cmap1_init( 0 );
                plfsurf3d( x, y, plf2ops_grid_row_major(), ( PLPointer ) & grid_row_major, XPTS, YPTS, MAG_COLOR | FACETED, NULL, 0 );
            }
            else if ( ifshade == 3 ) // magnitude colored plot with contours
            {
                cmap1_init( 0 );
                plfsurf3d( x, y, plf2ops_grid_col_major(), ( PLPointer ) & grid_col_major, XPTS, YPTS, MAG_COLOR | SURF_CONT | BASE_CONT, clevel, nlevel );
            }
            else // magnitude colored plot with contours and index limits.
            {
                cmap1_init( 0 );
                plsurf3dl( x, y, (const PLFLT * const *) zlimited, XPTS, YPTS, MAG_COLOR | SURF_CONT | BASE_CONT, clevel, nlevel, indexxmin, indexxmax, indexymin, indexymax );
            }
        }
    }

// Clean up

    free( (void *) x );
    free( (void *) y );
    plFree2dGrid( z, XPTS, YPTS );
    free( (void *) z_row_major );
    free( (void *) z_col_major );

    plFree2dGrid( zlimited, XPTS, YPTS );
    free( (void *) indexymin );
    free( (void *) indexymax );

    plend();

    exit( 0 );
}
Ejemplo n.º 7
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);
}
Ejemplo n.º 8
0
int
main(int argc, char *argv[])
{
  int i, j, k;
  PLFLT *x, *y, **z;
  PLFLT xx, yy;
  int nlevel = LEVELS;
  PLFLT clevel[LEVELS];
  PLFLT zmin, zmax, step;

  /* Parse and process command line arguments */

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

  /* Initialize plplot */

  plinit();

  x = (PLFLT *) calloc(XPTS, sizeof(PLFLT));
  y = (PLFLT *) calloc(YPTS, sizeof(PLFLT));

  plAlloc2dGrid(&z, XPTS, YPTS);
  for (i = 0; i < XPTS; i++) {
    x[i] = 3. * (double) (i - (XPTS / 2)) / (double) (XPTS / 2);
  }

  for (i = 0; i < YPTS; i++)
    y[i] = 3.* (double) (i - (YPTS / 2)) / (double) (YPTS / 2);

  for (i = 0; i < XPTS; i++) {
    xx = x[i];
    for (j = 0; j < YPTS; j++) {
      yy = y[j];
      z[i][j] = 3. * (1.-xx)*(1.-xx) * exp(-(xx*xx) - (yy+1.)*(yy+1.)) -
	10. * (xx/5. - pow(xx,3.) - pow(yy,5.)) * exp(-xx*xx-yy*yy) -
	1./3. * exp(-(xx+1)*(xx+1) - (yy*yy));
		 
      if(0) { /* Jungfraujoch/Interlaken */
	if (z[i][j] < -1.)
	  z[i][j] = -1.;
      }
    }
  }

  plMinMax2dGrid(z, XPTS, YPTS, &zmax, &zmin);  
  step = (zmax - zmin)/(nlevel+1);
  for (i=0; i<nlevel; i++)
    clevel[i] = zmin + step + step*i;

  cmap1_init();
  for (k = 0; k < 2; k++) {
    for (i=0; i<4; i++) {
      pladv(0);
      plcol0(1);
      plvpor(0.0, 1.0, 0.0, 0.9);
      plwind(-1.0, 1.0, -1.0, 1.5);
      plw3d(1.0, 1.0, 1.2, -3.0, 3.0, -3.0, 3.0, zmin, zmax, alt[k], az[k]);
      plbox3("bnstu", "x axis", 0.0, 0,
	     "bnstu", "y axis", 0.0, 0,
	     "bcdmnstuv", "z axis", 0.0, 4);

      plcol0(2);

      /* wireframe plot */
      if (i==0)
	plmesh(x, y, z, XPTS, YPTS, opt[k]);

      /* magnitude colored wireframe plot */
      else if (i==1)
	plmesh(x, y, z, XPTS, YPTS, opt[k] | MAG_COLOR);

      /* magnitude colored wireframe plot with sides */
      else if (i==2)
	plot3d(x, y, z, XPTS, YPTS, opt[k] | MAG_COLOR, 1);

      /* magnitude colored wireframe plot with base contour */
      else if (i==3)
	plmeshc(x, y, z, XPTS, YPTS, opt[k] | MAG_COLOR | BASE_CONT,
		clevel, nlevel);

      plcol0(3);
      plmtex("t", 1.0, 0.5, 0.5, title[k]);
    }
  }

/* Clean up */
  
  free((void *) x);
  free((void *) y);
  plFree2dGrid(z, XPTS, YPTS);

  plend();

  exit(0);
}
Ejemplo n.º 9
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 );
}
Ejemplo n.º 10
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 );
}
Ejemplo n.º 11
0
static void
label_box(const char *xopt, PLFLT xtick1, const char *yopt, PLFLT ytick1)
{
    static char string[40];
    PLINT lfx, lix, llx, lmx, lnx, ltx;
    PLINT lfy, liy, lly, lmy, lny, lty, lvy;
    PLFLT vpwxmi, vpwxma, vpwymi, vpwyma;
    PLFLT vpwxmin, vpwxmax, vpwymin, vpwymax;
    PLFLT pos, tn, tp, offset, height;

/* Set plot options from input */

    lfx = plP_stsearch(xopt, 'f');
    lix = plP_stsearch(xopt, 'i');
    llx = plP_stsearch(xopt, 'l');
    lmx = plP_stsearch(xopt, 'm');
    lnx = plP_stsearch(xopt, 'n');
    ltx = plP_stsearch(xopt, 't');

    lfy = plP_stsearch(yopt, 'f');
    liy = plP_stsearch(yopt, 'i');
    lly = plP_stsearch(yopt, 'l');
    lmy = plP_stsearch(yopt, 'm');
    lny = plP_stsearch(yopt, 'n');
    lty = plP_stsearch(yopt, 't');
    lvy = plP_stsearch(yopt, 'v');

    plgvpw(&vpwxmin, &vpwxmax, &vpwymin, &vpwymax);
/* n.b. large change; vpwxmi always numerically less than vpwxma, and
 * similarly for vpwymi */
    vpwxmi = (vpwxmax > vpwxmin) ? vpwxmin : vpwxmax;
    vpwxma = (vpwxmax > vpwxmin) ? vpwxmax : vpwxmin;
    vpwymi = (vpwymax > vpwymin) ? vpwymin : vpwymax;
    vpwyma = (vpwymax > vpwymin) ? vpwymax : vpwymin;

/* Write horizontal label(s) */

    if ((lmx || lnx) && ltx) {
	PLINT xmode, xprec, xdigmax, xdigits, xscale;

	plgxax(&xdigmax, &xdigits);
	pldprec(vpwxmi, vpwxma, xtick1, lfx, &xmode, &xprec, xdigmax, &xscale);

	tp = xtick1 * (1. + floor(vpwxmi / xtick1));
	for (tn = tp; BETW(tn, vpwxmi, vpwxma); tn += xtick1) {
	    plform(tn, xscale, xprec, string, llx, lfx);
	    height = lix ? 1.75 : 1.5;
	    pos = (vpwxmax > vpwxmin)? 
	        (tn - vpwxmi) / (vpwxma - vpwxmi):
	        (vpwxma - tn) / (vpwxma - vpwxmi);
  	    if (lnx)
		plmtex("b", height, pos, 0.5, string);
	    if (lmx)
		plmtex("t", height, pos, 0.5, string);
	}
	xdigits = 2;
	plsxax(xdigmax, xdigits);

    /* Write separate exponential label if mode = 1. */

	if (!llx && xmode) {
	    pos = 1.0;
	    height = 3.2;
	    sprintf(string, "(x10#u%d#d)", (int) xscale);
	    if (lnx)
		plmtex("b", height, pos, 0.5, string);
	    if (lmx)
		plmtex("t", height, pos, 0.5, string);
	}
    }

/* Write vertical label(s) */

    if ((lmy || lny) && lty) {
	PLINT ymode, yprec, ydigmax, ydigits, yscale;

	plgyax(&ydigmax, &ydigits);
	pldprec(vpwymi, vpwyma, ytick1, lfy, &ymode, &yprec, ydigmax, &yscale);

	ydigits = 0;
	tp = ytick1 * (1. + floor(vpwymi / ytick1));
	for (tn = tp; BETW(tn, vpwymi, vpwyma); tn += ytick1) {
	    plform(tn, yscale, yprec, string, lly, lfy);
	    pos = (vpwymax > vpwymin)? 
	        (tn - vpwymi) / (vpwyma - vpwymi):
	        (vpwyma - tn) / (vpwyma - vpwymi);
	    if (lny) {
		if (lvy) {
		    height = liy ? 1.0 : 0.5;
		    plmtex("lv", height, pos, 1.0, string);
		} else {
		    height = liy ? 1.75 : 1.5;
		    plmtex("l", height, pos, 0.5, string);
		}
	    }
	    if (lmy) {
		if (lvy) {
		    height = liy ? 1.0 : 0.5;
		    plmtex("rv", height, pos, 0.0, string);
		} else {
		    height = liy ? 1.75 : 1.5;
		    plmtex("r", height, pos, 0.5, string);
		}
	    }
	    ydigits = MAX(ydigits, strlen(string));
	}
	if (!lvy)
	    ydigits = 2;

	plsyax(ydigmax, ydigits);

    /* Write separate exponential label if mode = 1. */

	if (!lly && ymode) {
	    sprintf(string, "(x10#u%d#d)", (int) yscale);
	    offset = 0.02;
	    height = 2.0;
	    if (lny) {
		pos = 0.0 - offset;
		plmtex("t", height, pos, 1.0, string);
	    }
	    if (lmy) {
		pos = 1.0 + offset;
		plmtex("t", height, pos, 0.0, string);
	    }
	}
    }
}
Ejemplo n.º 12
0
void
plot4(void)
{
    int i, j;
    PLFLT dtr, theta, dx, dy, r;
    char text[3];
    PLFLT x0[361], y0[361];
    PLFLT x[361], y[361];

    dtr = PI / 180.0;
    for (i = 0; i <= 360; i++) {
	x0[i] = cos(dtr * i);
	y0[i] = sin(dtr * i);
    }

/* Set up viewport and window, but do not draw box */

    plenv(-1.3, 1.3, -1.3, 1.3, 1, -2);
    for (i = 1; i <= 10; i++) {
	for (j = 0; j <= 360; j++) {
	    x[j] = 0.1 * i * x0[j];
	    y[j] = 0.1 * i * y0[j];
	}

/* Draw circles for polar grid */

	plline(361, x, y);
    }

    plcol0(2);
    for (i = 0; i <= 11; i++) {
	theta = 30.0 * i;
	dx = cos(dtr * theta);
	dy = sin(dtr * theta);

/* Draw radial spokes for polar grid */

	pljoin(0.0, 0.0, dx, dy);
	sprintf(text, "%d", ROUND(theta));

/* Write labels for angle */

/* Slightly off zero to avoid floating point logic flips at 90 and 270 deg. */
	if (dx >= -0.00001)
	    plptex(dx, dy, dx, dy, -0.15, text);
	else
	    plptex(dx, dy, -dx, -dy, 1.15, text);
    }

/* Draw the graph */

    for (i = 0; i <= 360; i++) {
	r = sin(dtr * (5 * i));
	x[i] = x0[i] * r;
	y[i] = y0[i] * r;
    }
    plcol0(3);
    plline(361, x, y);

    plcol0(4);
    plmtex("t", 2.0, 0.5, 0.5,
	   "#frPLplot Example 3 - r(#gh)=sin 5#gh");
    plflush();
}
Ejemplo n.º 13
0
int
main( int argc, const char *argv[] )
{
    char  text[10];
    int   i, j, k, l;
    PLFLT x, y;

// Parse and process command line arguments

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

// Initialize plplot

    plinit();

    plfontld( 0 );
    for ( l = 0; l < 20; l++ )
    {
        if ( l == 2 )
            plfontld( 1 );
        pladv( 0 );

        // Set up viewport and window

        plcol0( 2 );
        plvpor( 0.15, 0.95, 0.1, 0.9 );
        plwind( 0.0, 1.0, 0.0, 1.0 );

        // Draw the grid using plbox

        plbox( "bcg", 0.1, 0, "bcg", 0.1, 0 );

        // Write the digits below the frame

        plcol0( 15 );
        for ( i = 0; i <= 9; i++ )
        {
            sprintf( text, "%d", i );
            plmtex( "b", 1.5, ( 0.1 * i + 0.05 ), 0.5, text );
        }

        k = 0;
        for ( i = 0; i <= 9; i++ )
        {
            // Write the digits to the left of the frame

            sprintf( text, "%d", base[l] + 10 * i );
            plmtex( "lv", 1.0, ( 0.95 - 0.1 * i ), 1.0, text );
            for ( j = 0; j <= 9; j++ )
            {
                x = 0.1 * j + 0.05;
                y = 0.95 - 0.1 * i;

                // Display the symbols

                plsym( 1, &x, &y, base[l] + k );
                k = k + 1;
            }
        }

        if ( l < 2 )
            plmtex( "t", 1.5, 0.5, 0.5, "PLplot Example 7 - PLSYM symbols (compact)" );
        else
            plmtex( "t", 1.5, 0.5, 0.5, "PLplot Example 7 - PLSYM symbols (extended)" );
    }
    plend();
    exit( 0 );
}