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

2.7.11 “Templates”

As I have noted before, the change of settings will influence only for the further plotting commands. This allows one to create template function which will contain settings and primitive drawing for often used plots. Correspondingly one may call this template-function for drawing simplification.

For example, let one has a set of points (experimental or numerical) and wants to compare it with theoretical law (for example, with exponent law \exp(-x/2), x \in [0, 20]). The template-function for this task is:

    void template(mglGraph *gr)
    {
        mglData  law(100);      // create the law
        law.Modify("exp(-10*x)");
        gr->Axis(mglPoint(0,0.0001), mglPoint(20,1), mglPoint(0,0.0001));
        gr->SetFunc(0,"lg(y)",0);   gr->dy = 0;
        gr->Plot(law,"r2");
        gr->Text(mglPoint(10,0.2),"Theoretical law: e^x","rL");
        gr->Label('x',"x val."); gr->Label('y',"y val.");
        gr->Axis(); gr->Grid("xy","g;"); gr->Box();
    }

At this, one will only write a few lines for data drawing:

    template(gr);     // apply settings and default drawing from template
    mglData dat("fname.dat"); // load the data
    // and draw it (suppose that data file have 2 columns)
    gr->Plot(dat.SubData(0),dat.SubData(1),"bx ");

A template-function can also contain settings for font, transparency, lightning, color scheme and so on.


© manpagez.com 2000-2024
Individual documents may contain additional copyright information.