3.6 FAQ

The plot does not appear

Check that points of the plot are located inside the bounding box and resize the bounding box using ranges function. Check that the data have correct dimensions for selected type of plot. Be sure that Finish() 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 by surf. See also, Hints. 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 build system. The reason is that I don’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 functionvoid mgl_fplot(HMGL graph, const char *fy, const char *stl, int n);

AT&T functionvoid mgl_fplot_(uintptr_t *graph, const char *fy, const char *stl, int *n, int ly, int ls);

Fortran users also should add C++ library by the option -lstdc++. If library was built with enable-double=ON (this default for v.2.1 and later) then all real numbers must be real*8. You can make it automatic if use option -fdefault-real-8.

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 use setlocale(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 constant LC_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 (including color/alpha range) will never be plotted. Second, special functions SetCutBox() and CutOff() define the condition when the points should be omitted (see Cutting). Last, you may change the transparency of a part of the plot by the help of functions surfa, surf3a (see Dual plotting). In 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 2.0, main classes (mglGraph and mglData) contains only inline functions and are acceptable for any compiler with the same binary files. However, if you plan to use widget classes (QMathGL, Fl_MathGL, ...) or to access low-level features (mglBase, mglCanvas, ...) then you have to recompile MathGL by yours compiler.

Note, that you have to make import library(-ies) *.lib for provided binary *.dll. This procedure depend on used compiler – please read documentation for yours compiler. For VisualStudio, it can be done by command lib.exe /DEF:libmgl.def /OUT:libmgl.lib.

How make FLTK/GLUT/Qt window which will display result of my calculations?

You need to put yours calculations or main event-handling loop in the separate thread. For static image you can give NULL as drawing function and call Update() function when you need to redraw it. For more details see Animation.

How I can build MathGL under Windows?

Generally, it is the same procedure as for Linux or MacOS – see section Installation. The simplest way is using the combination CMake+MinGW. Also you may 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-gui configurator and build the MathGL itself.

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 build system (cmake files) was written mostly by D.Kulagin, and the export to PRC/PDF was written mostly by M.Vidassov.

How can I display a bitmap on the figure?

You can import data into a mglData instance by function import and display it by dens 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’t find the appropriate class then you can create your own widget that displays a bitmap using mglCanvas::GetRGB().

How can I create 3D in PDF?

Just use WritePRC() method which also create PDF file if enable-pdf=ON at MathGL configure.

How can I create TeX figure?

Just use WriteTEX() method which create LaTeX files with figure itself ‘fname.tex’, with MathGL colors ‘mglcolors.tex’ and main file ‘mglmain.tex’. Last one can be used for viewing image by command like pdflatex mglmain.tex.

Can I use MathGL in JavaScript?

Yes, sample JavaScript file is located in texinfo/ folder of sources. You should provide JSON data with 3d image for it (can be created by WriteJSON() method). Script allows basic manipulation with plot: zoom, rotation, shift. Sample of JavaScript pictures can be found in http://mathgl.sf.net/json.html.

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->LoadFont(fontname,path);. Here fontname is the base font name like ‘STIX2’ and path sets the location of font files. Use gr->RestoreFont(); to start using the default font.

How can I draw tick out of a bounding box?

Just set a negative value in ticklen. For example, use gr->SetTickLen(-0.1);.

How can I prevent text rotation?

Just use SetRotatedText(false). Also you can use axis style ‘U’ for disable only tick labels rotation.

What is *.so? What is gcc? How I can use make?

They are standard GNU tools. There is special FAQ about its usage under Windows – http://www.mingw.org/wiki/FAQ.

How can I draw equal axis range even for rectangular image?

Just use Aspect(NAN,NAN) for each subplot, or at the beginning of the drawing.

How I can set transparent background?

Just use code like Clf("r{A5}"); or prepare PNG file and set it as background image by call LoadBackground("fname.png");.

How I can reduce "white" edges around bounding box?

The simplest way is to use subplot style. However, you should be careful if you plan to add colorbar or rotate plot – part of plot can be invisible if you will use non-default subplot style.

Can I combine bitmap and vector output in EPS?

Yes. Sometimes you may have huge surface and a small set of curves and/or text on the plot. You can use function rasterize just after making surface plot. This will put all plot to bitmap background. At this later plotting will be in vector format. For example, you can do something like following:

gr->Surf(x, y, z);
gr->Rasterize(); // make surface as bitmap
gr->Axis();
gr->WriteFrame("fname.eps");
Why I couldn’t use name ‘I’ for variable?

MathGL support C99 standard, where ‘I’ is reserved for imaginary unit. If you still need this name, then just use

#undef I

after including MathGL header files.

How I can create MPEG video from plots?

You can save each frame into JPEG with names like ‘frame0001.jpg’, ‘frame0002.jpg’, ... Later you can use ImageMagic to convert them into MPEG video by command convert frame*.jpg movie.mpg. See also MPEG.