[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
1.6.2 Python interface
MathGL provides the interface to a set of languages via SWIG library. Some of these languages support classes. The typical example is Python – which is named in this chapter</samp>’s title.
To use Python classes just execute ‘import mathgl’. The simplest example will be:
import mathgl a=mathgl.mglGraph() a.Box() a.WritePNG(</samp>’test.png</samp>’)
Alternatively you can import all classes from mathgl
module and easily access MathGL classes like this:
from mathgl import * a=mglGraph() a.Box() a.WritePNG(</samp>’test.png</samp>’)
This becomes useful if you create many mglData
objects, for example.
There are 2 classes in Python interface:
-
mglGraph
– provide practically the same functionality as C++ classmglGraph
(see section MathGL core). But it is not an abstract class and it allows one to select at construction stage which plotter (ZB or PS and so on) will be used. -
mglData
– is exactly the same class as C++mglData
(see section mglData class), but an additional feature to access data values is added. You can use a construct like this:dat[i]=sth;
orsth=dat[i]
where flat representation of data is used (i.e., i can be in range 0...nx*nx*nz-1). You can also import NumPy arrays as input arguments:mgl_dat = mglData(numpy_dat);
.To use Python classes just execute ‘import mathgl’. The simplest example will be:
import mathgl a=mathgl.mglGraph() a.Box() a.WritePNG(</samp>’test.png</samp>’)
Alternatively, you can import all the classes from
mathgl
module and easily access MathGL classes:from mathgl import * a=mglGraph() a.Box() a.WritePNG(</samp>’test.png</samp>’)
This is useful if you create many
mglData
objects, for example.There are 2 classes in Python interface:
-
mglGraph
– provide practically the same functionality as C++ classmglGraph
(see section MathGL core). But it is not an abstract class and it allows one to select at the construction stage which plotter (ZB or PS and so on) will be used. -
mglData
– is exactly the same class as C++mglData
(see section mglData class), but an additional feature to access data values is added. You can use a construct like this:dat[i]=sth;
orsth=dat[i]
where flat representation of data is used (i.e., i can be in range 0...nx*nx*nz-1).
There is one main difference from C++ classes – Python class
mglGraph
does not have variables (options). All the corresponding features are moved to methods. The core of MathGL Python class is the mglGraph class. It contains a lot of plotting functions for 1D, 2D and 3D plots. So most of the sections describe its methods. Its constructor has the following arguments:- Constructor on mglGraph (Python):
mglGraph (
int
kind=0
,int
width=600
,int
height=400
) Create the instance of class mglGraph with specified sizes width and height. Parameter type may have following values: ‘0’ – use
mglGraphZB
plotter (default), ‘1’ – usemglGraphPS
plotter, ‘2’ – usemglGraphGL
plotter, ‘3’ – usemglGraphIDTF
plotter.
-
There is one difference from C++ classes – Python class mglGraph
does not have variables (options). All the corresponding features are moved to methods.
The core of MathGL Python class is the mglGraph class. It contains a lot of plotting functions for 1D, 2D and 3D plots. So most of the sections describe its methods. Its constructor has the following arguments:
- Constructor on mglGraph (Python):
mglGraph (
int
kind=0
,int
width=600
,int
height=400
) Create the instance of class mglGraph with specified sizes width and height. Parameter type may have following values: ‘0’ – use
mglGraphZB
plotter (default), ‘1’ – usemglGraphPS
plotter, ‘2’ – usemglGraphGL
plotter, ‘3’ – usemglGraphIDTF
plotter.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |