manpagez: man pages & more
info mathgl
Home | html | info | man
[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.4.1 Plots for 1D data

Term “1D data” means that data depend on single index (parameter) like curve in parametric form {x(i),y(i),z(i)}, i=1...n. There are 5 generally different types of data representations: simple line plot, line plot with filling under it, stairs plot, bar plot and vertical lines (see section 1D plotting). Each type of plotting has similar interface. There are 3D version and two 2D versions. One of last requires single array. The parameters of line and marks (see section Line styles) are specified by the string argument. If the string parameter is NULL then solid line with color from palette is used (see section Pallete and colors).

Below I shall show the features of 1D plotting on base of Plot() function (see section Plot). Let us start from sinus plot:

    int sample(mglGraph *gr, void *)
    {
        mglData y0(50); 	y0.Modify("sin(pi*(2*x-1))");
        gr->SubPlot(2,2,0);
        gr->Plot(y0);   	gr->Box();

Style of line is not specified in Plot() function. So MathGL uses the solid line with first color of palette (this is blue). Next subplot shows array y1 with 2 rows:

        gr->SubPlot(2,2,1);
        mglData y1(50,2);
        y1.Modify("sin(pi*2*x-pi)");
        y1.Modify("cos(pi*2*x-pi)/2",1);
        gr->Plot(y1);   	gr->Box();

As previously I did not specify the style of lines. As a result, MathGL again uses solid line with next colors in palette (there are green and red). Now let us plot a circle on the same subplot. The circle is parametric curve x=cos(\pi t), y=sin(\pi t). I will set the color of the circle (dark yellow, ‘Y’) and put marks ‘+’ at point position:

        mglData x(50);  	x.Modify("cos(pi*2*x-pi)");
        gr->Plot(x,y0,"Y+");

Note that solid line is used because I did not specify the type of line. The same picture can be achieved by Plot2() function. Let us draw ellipse by orange dash line:

        gr->Plot2(y1,"q|");

Drawing in 3D space is mostly the same. Let us draw spiral with default line style. Now its color is 4-th color from palette (this is cyan):

        gr->SubPlot(2,2,2);	gr->Rotate(60,40);
        mglData z(50);  	z.Modify("2*x-1");
        gr->Plot(x,y0,z);	gr->Box();

Function Plot3() does 3D curve plot but for single array. Use it to put circle marks on the previous plot:

        mglData y2(10,3);	y2.Modify("cos(pi*(2*x-1+y))");
        y2.Modify("2*x-1",2);
        gr->Plot3(y2,"bo ");

Note that line style is empty ‘ ’ here. Usage of other 1D plotting functions looks similar:

        gr->SubPlot(2,2,3);	gr->Rotate(60,40);
        gr->Bars(x,y0,z,"r");	gr->Box();
        return 0;
    }
../png/sample8

Example of 1D data plot


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]
© manpagez.com 2000-2024
Individual documents may contain additional copyright information.