[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
1.5 FAQ
- The plot does not appear
Check that points of the plot lie inside the bounding box and resize the bounding box using
Axis()
function. Check that the data have correct dimensions for selected type of plot. Be sure thatFinish()
is called after the plotting functions (or be sure that the plot is saved to a file). Sometimes the light reflection from flat surfaces (like,Dens()
) can look as if the plot were absent.- I can not find some special kind of plot.
Most “new” types of plots can be created by using the existing drawing functions. For example, the surface of curve rotation can be created by a special function
Torus()
, or as a parametrically specified surface bySurf()
. See also, Hints and MathGL examples of MathGL. If you can not find a specific type of plot, please e-mail me and this plot will appear in the next version of MathGL library.- Should I know some graphical libraries (like OpenGL) before using the MathGL library?
No. The MathGL library is self-contained and does not require the knowledge of external libraries.
- In which language is the library written? For which languages does it have an interface?
The core of the MathGL library is written in C++. But there are interfaces for: pure C, Fortran, Pascal, Forth, and its own command language MGL. Also there is a large set of interpreted languages, which are supported (Python, Java, ALLEGROCL, CHICKEN, Lisp, CFFI, C#, Guile, Lua, Modula 3, Mzscheme, Ocaml, Octave, Perl, PHP, Pike, R, Ruby, Tcl). These interfaces are written using SWIG (both pure C functions and classes) but only the interface for Python and Octave is included in the autoconf/automake script. The reason is that I don</samp>’t know any other interpreted languages :(. Note that most other languages can use (link to) the pure C functions.
- How can I use MathGL with Fortran?
You can use MathGL as is with
gfortran
because it uses by default the AT&T notation for external functions. For other compilers (like Visual Fortran) you have to switch on the AT&T notation manually. The AT&T notation requires that the symbol ‘_’ is added at the end of each function name, function argument(s) is passed by pointers and the string length(s) is passed at the end of the argument list. For example:C function –
void mgl_fplot(HMGL graph, const char *fy, const char *stl, int n);
AT&T function –
void mgl_fplot_(uintptr_t *graph, const char *fy, const char *stl, int *n, int ly, int ls);
- I have a class Foo and a drawing method Foo::draw(mglGraph *gr). How I can use it in FLTK or GLUT window?
The member-functions of classes have a hidden parameter (the pointer to a class instance) in C++. So, their direct usage is impossible. The solution is to write an interface function:
int foo_draw(mglGraph *gr, void *par) { ((Foo *)foo)->draw(gr); }
and to use it in the call of
Window()
function:gr->Window(argc,argv,foo_draw,"Title",this);
Alternatively you can inherit your class from
mglDraw
class and use the functions likegr->Window(argc, argv, foo, "Title");
.- How can I print in Russian/Spanish/Arabic/Japanese, and so on?
The standard way is to use Unicode encoding for the text output. But the MathGL library also has interface for 8-bit (char *) strings with internal conversion to Unicode. This conversion depends on the current locale OS. You may change it by
setlocale()
function. For example, for Russian text in CP1251 encoding you may usesetlocale(LC_CTYPE, "ru_RU.cp1251");
(under MS Windows the name of locale may differ –setlocale(LC_CTYPE, "russian_russia.1251")
). I strongly recommend not to use the constantLC_ALL
in the conversion. Since it also changes the number format, it may lead to mistakes in formula writing and reading of the text in data files. For example, the program will await a ‘,’ as a decimal point but the user will enter ‘.’.- How can I exclude a point or a region of plot from the drawing?
There are 3 general ways. First, the point with
NAN
value as one of the coordinates will never be plotted. Second, special variables CutMin, CutMax or functionCutOff
() define the condition when the points should be omitted (see section Cutting). Last, you may change the transparency of a part of the plot by the help of functionsSurfA()
,Surf3A()
(see section Dual plotting). In this last case the transparency is switched on smoothly.- I use VisualStudio, CBuilder or some other compiler (not MinGW/gcc). How can I link the MathGL library?
In version 1.10, you can use the header file
#include <mgl/mgl_w.h>
which contains wrapper C++ classes, which should be acceptable for any compiler. Note, that wrapper classes are incompatible with classes in usual headers and you should use only one of them (wrapper or usual)! However, I recommend to use the usual headers if you use GNU compilers (like MinGW).- How I can build MathGL under Windows?
The simplest way is using the combination CMake+MinGW. Also you need some extra libraries like GSL, PNG, JPEG and so on. All of them can be found at http://gnuwin32.sourceforge.net/packages.html. After installing all components, just run CMake configurator and make the MathGL itself.
- How I can create FLTK/GLUT/Qt window in parallel with calculation?
You should create a separate thread for processing window messages. The cross-platform way is using the
pthread
library. You can update the data by callingmglGraphFLTK::Update()
function. The code can look like this://----------------------------------------------------------------------------- #include <mgl/mgl_fltk.h> #include <pthread.h> #include <unistd.h> mglPoint pnt; // some global variable for changable data //----------------------------------------------------------------------------- int sample(mglGraph *gr, void *) { gr->Box(); gr->Line(mglPoint(),pnt,"Ar2"); // just draw a vector return 0; } //----------------------------------------------------------------------------- void *mgl_fltk_tmp(void *) { mglFlRun(); return 0; } int main (int argc, char ** argv) { mglGraphFLTK gr; gr.Window(argc,argv,sample,"test"); // create window static pthread_t tmp; pthread_create(&tmp, 0, mgl_fltk_tmp, 0); pthread_detach(tmp); // run window handling in the separate thread for(int i=0;i<10;i++) // do calculation { sleep(1); // which can be very long pnt = mglPoint(2*mgl_rnd()-1,2*mgl_rnd()-1); gr.Update(); // update window } return 0; // finish calculations and close the window } //-----------------------------------------------------------------------------
- How many people write this library?
Most of the library was written by one person. This is a result of nearly a year of work (mostly in the evening and on holidays): I spent half a year to write the kernel and half a year to a year on extending, improving the library and writing documentation. This process continues now :). The autoconf/automake script was written mostly by D.Kulagin, and the export to IDTF was written mostly by M.Vidassov.
- How can I display a bitmap on the figure?
You can import data into a
mglData
instance and display it byDens()
function. For example, for black-and-white bitmap you can use the code:mglData bmp; bmp.Import("fname.png","wk"); gr->Dens(bmp,"wk");
.- How can I use MathGL in Qt, FLTK, wxWidgets etc.?
There are special classes (widgets) for these libraries: QMathGL for Qt, Fl_MathGL for FLTK and so on. If you don</samp>’t find the appropriate class then you can create your own widget that displays a bitmap using mglGraphAB::GetBits().
- How can I create U3D file (make 3D in PDF)?
There are 2 steps: first you should create IDTF file, and later convert it to U3D. You can use U3D tools for converting IDTF file to U3D. It needs libharu 2.1.0 or later. For installation use
./bootstrap, ./configure, make, sudo make install
. It provides IDTFConverter program for converting text files *.idtf to binary files *.u3d. The latter can be included into PDF.- How I can change the font family?
First, you should download new font files from here or from here. Next, you should load the font files into mglGraph class instance gr by the following command:
gr->SetFont(new mglFont(fontname,path));
. Here fontname is the base font name like ‘STIX’ and path sets the location of font files. Usegr->SetFont(NULL);
to start using the default font.- How can I draw tick out of a bounding box?
Just set a negative value for TickLen. For example, use
gr->SetTickLen(-0.1);
.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |