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

2.4.2 Plots for 2D data

Surfaces Surf() and other 2D plots (see section 2D plotting) are drown the same simpler as 1D one. The difference is that the string parameter specifies not by line style but by the color scheme of the plot (see section Color scheme). Here I draw attention on 4 most interesting color schemes. There is gray scheme where color is changed from black to white (string ‘kw’) or from white to black (string ‘wk’). Another scheme is useful for accentuation of negative (by blue color) and positive (by red color) regions on plot (string ‘"BbwrR"’). Last one is the popular “jet” scheme (string ‘"BbcyrR"’).

Now I shall show the example of a surface drawing. At first let us switch lightning on

    int sample(mglGraph *gr, void *)
    {
        gr->Light(true);	gr->Light(0,mglPoint(0,0,1));

and draw the surface, considering coordinates x,y to be uniformly distributed in interval Min*Max

        mglData a0(50,40);
        a0.Modify("0.6*sin(2*pi*x)*sin(3*pi*y)+0.4*cos(3*pi*(x*y))");
        gr->SubPlot(2,2,0);	gr->Rotate(60,40);
        gr->Surf(a0);		gr->Box();

Color scheme was not specified. So previous color scheme is used. In this case it is default color scheme (“jet”) for the first plot. Next example is a sphere. The sphere is parametrically specified surface:

        mglData x(50,40),y(50,40),z(50,40);
        x.Modify("0.8*sin(2*pi*x)*sin(pi*y)");
        y.Modify("0.8*cos(2*pi*x)*sin(pi*y)");
        z.Modify("0.8*cos(pi*y)");
        gr->SubPlot(2,2,1);	gr->Rotate(60,40);
        gr->Surf(x,y,z,"BbwrR");gr->Box();

I set color scheme to "BbwrR" that corresponds to red top and blue bottom of the sphere.

Surfaces will be plotted for each of slice of the data if nz>1. Next example draws surfaces for data arrays with nz=3:

        mglData a1(50,40,3);
        a1.Modify("0.6*sin(2*pi*x)*sin(3*pi*y)+0.4*cos(3*pi*(x*y))");
        a1.Modify("0.6*cos(2*pi*x)*cos(3*pi*y)+0.4*sin(3*pi*(x*y))",1);
        a1.Modify("0.6*cos(2*pi*x)*cos(3*pi*y)+0.4*cos(3*pi*(x*y))",2);
        gr->SubPlot(2,2,2);	gr->Rotate(60,40);
        gr->Alpha(true);
        gr->Surf(a1);		gr->Box();

Note, that it may entail a confusion. However, if one will use density plot then the picture will look better:

        gr->SubPlot(2,2,3);	gr->Rotate(60,40);
        gr->Dens(a1);		gr->Box();
        return 0;
    }

Note, that the previous color scheme is used in last plots because there are no direct specification of the one.

../png/sample9

Example of surface plot for 2D data

Drawing of other 2D plots is analogous. The only peculiarity is the usage of flag ‘#’. By default this flag switches on the drawing of a grid on plot (Grid() or Mesh() for plots in plain or in volume). However, for isosurfaces (including surfaces of rotation Axial()) this flag switches the face drawing off. Figure becomes wired. The following code gives example of flag ‘#’ using (compare with normal function drawing as in its description):

    int sample(mglGraph *gr, void *)
    {
        gr->Alpha(true);	gr->Light(true);	gr->Light(0,mglPoint(0,0,1));
        mglData a(30,20);
        a.Modify("0.6*sin(2*pi*x)*sin(3*pi*y) + 0.4*cos(3*pi*(x*y))");

        gr->SubPlot(2,2,0);	gr->Rotate(40,60);
        gr->Surf(a,"BbcyrR#");		gr->Box();
        gr->SubPlot(2,2,1);	gr->Rotate(40,60);
        gr->Dens(a,"BbcyrR#");		gr->Box();
        gr->SubPlot(2,2,2);	gr->Rotate(40,60);
        gr->Cont(a,"BbcyrR#");		gr->Box();
        gr->SubPlot(2,2,3);	gr->Rotate(40,60);
        gr->Axial(a,"BbcyrR#");		gr->Box();
        return 0;
    }
../png/samplea

Example of 2D data plot with color scheme contained ‘#’ symbol


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