| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
9. Python interface
MathGL provide the interface to a set of languages via SWIG library. Some of these languages support classes. The typical example is Python – which is denoted in the chapter title.
To use Python classes just execute ‘import mathgl’. The simplest example will be:
import mathgl
a=mathgl.mglGraph()
a.Box()
a.WritePNG('test.png')
Alternatively you can import all classes from mathgl module and easely access MathGL classes:
from mathgl import *
a=mglGraph()
a.Box()
a.WritePNG('test.png')
It become aloud if you will create many mglData object.
There are 2 classes in Python interface:
-
mglGraph– provide practically the same functionality as C++ classmglGraph(see section MathGL core). But it is not abstract class and it allows one to select at construction stage which plotter (ZB or PS and so on) will be used. -
mglData– is absolutely the same class as C++mglData(see section mglData class). But an additional feature to acess data values is added. You can use construction like this:dat[i]=sth;orsth=dat[i]at this flat representation of data is used (i.e., i can be in range 0...nx*nx*nz-1.
There is main difference from C++ classes – Python class mglGraph don't have variables (options). All corresponding features are moved to methods.
The core of MathGL Python class is mglGraph class. It contains a lot of plotting functions for 1D, 2D and 3D plots. So most of sections is describe its methods. Its constructor have following arguments:
- Constructor on mglGraph (Python):
mglGraph (intkind=0,intwidth=600,intheight=400) Create the instance of class mglGraph with specified sizes width and height. Parameter type may have following values: ‘0’ – use
mglGraphZBplotter (default), ‘1’ – usemglGraphPSplotter, ‘2’ – usemglGraphGLplotter, ‘3’ – usemglGraphIDTFplotter.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
