Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to label axes in Mayavi using LaTeX math symbols?

Tags:

python

mayavi

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.

like image 585
nye17 Avatar asked Sep 15 '11 04:09

nye17


2 Answers

Mayavi does not support LaTeX symbols sadly.

like image 123
freethebees Avatar answered Sep 19 '22 00:09

freethebees


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!

like image 28
greeeeeeen Avatar answered Sep 20 '22 00:09

greeeeeeen