enthought / mayavi

3D visualization of scientific data in Python
http://docs.enthought.com/mayavi/mayavi/
Other
1.3k stars 285 forks source link

Add support for TeX in axis labels and figure titles in mlab #267

Open charles92 opened 8 years ago

charles92 commented 8 years ago

It would be very convenient to have TeX or LaTeX symbols for plots of scientific datasets, as is in Matplotlib.

IVIUPPET commented 8 years ago

Yes, coming from Matlab and sick of its headaches, this would be very useful. Matplotlib supports it, though I'm glad the devs worked to get MayaVi going on Python 3.5 at all. Matplotlib's 3D graphing is not quite good enough for most applications.

MuellerSeb commented 6 years ago

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()
MuellerSeb commented 5 years ago

You can install it now with:

pip install mlabtex
prabhuramachandran commented 5 years ago

That is very cool! Thank you for sharing!

SimonEnsemble commented 3 years ago

thanks! I'm looking for a way to use LaTeX in the axis labels, though.