9

I'm importing mayavi in a python script to display some 3D data set, it turns out the following naive axes labeling doesn't work

from mayavi import mlab
axes =mlab.axes(xlabel='$\alpha$', ylabel='$\beta$', zlabel='$\sigma$')

Any ideas? I cannot find the solution from either google or the user manual.

nye17
  • 12,857
  • 11
  • 58
  • 68
  • 1
    Does Mayavi definitely support TeX labels? I can't find any mention of it in the documentation. In Matplotlib, there is a `usetex` option that I think is off by default - maybe there is something similar? – James Feb 15 '12 at 13:43

5 Answers5

5

Mayavi does not support LaTeX symbols sadly.

freethebees
  • 957
  • 10
  • 24
2

I wrote a package to enable latex support for mayavi called mlabtex: https://github.com/MuellerSeb/mlabtex

It produces an image rendered with matplotlib and uses this as a texture for a mlab.surf. The interface is similar to mlab.text3d.

With this, you can do something like that:

import os
os.environ['QT_API'] = 'pyqt'
os.environ['ETS_TOOLKIT'] = 'qt4'
from mayavi import mlab
from mlabtex import mlabtex

TEXT = (r'Sebastian M\"uller, ' +
        r'$f(x)=\displaystyle\sum_{n=0}^\infty ' +
        r'f^{(n)}(x_0)\cdot\frac{(x-x_0)^n}{n!}$')

tex = mlabtex(0., 0., 0.,
              TEXT,
              color=(0., 0., 0.),
              orientation=(30., 0., 0.),
              dpi=1200)
mlab.axes()
mlab.show()

Latex in Mayavi To label the axes, you can now place the text there by hand.

Good luck!

MuellerSeb
  • 796
  • 6
  • 11
1

The thread is a bit old, but the problem is still not resolved. For those, who are still interested in using Latex text in mayavi could have a look at this site:

https://pgi-jcns.fz-juelich.de/portal/pages/latex-mayavi.html

There, a workaround is presented, where a latex document is converted to a png file, which is again imported to mayavi. Good luck!

MuellerSeb
  • 796
  • 6
  • 11
-1

As noted in the answer by @freethebees, LaTeX labels are not supported by Mayavi. See my answer to this question as a way of achieving LaTeX labels on a Mayavi scene. You can export the Mayavi scene (without axes) as an image and import into PGFPlots, along with a coordinate transform to place the LaTeX-drawn axes correctly.

Example result:

enter image description here

tsj
  • 758
  • 3
  • 23
-4

Try putting an r in front of each string

from mayavi import mlab
axes =mlab.axes(xlabel=r'$\alpha$', ylabel=r'$\beta$', zlabel=r'$\sigma$')
Zykx
  • 183
  • 1
  • 2
  • 8
  • This is explained [here](http://docs.python.org/reference/lexical_analysis.html#string-literals). Without the `r` prefix, `\a` and `\b` are interpreted as escape sequences. I don't think this should be necessary for `'$\sigma$'`, as `\s` doesn't appear to be a recognised escape sequence. – James Feb 15 '12 at 13:35
  • 1
    you sure it works? I don't have the resources available to test this, but presumably I think the question is more related to whether mayavi supports TeX at all. – nye17 Feb 15 '12 at 19:09
  • 1
    @Zykx: doesn't work for me. Please provide a complete example. – Adobe Aug 30 '14 at 16:39
  • @Zykx as already mentioned by the others, this answer is not applicable to Mayavi, please consider reviewing it... – Saullo G. P. Castro Sep 17 '14 at 06:07