开发者

How to label axes in Mayavi using LaTeX math symbols?

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.


Mayavi does not support LaTeX symbols sadly.


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()

How to label axes in Mayavi using LaTeX math symbols?

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

Good luck!


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!


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:

How to label axes in Mayavi using LaTeX math symbols?


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$')
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜