John Mahoney

mayavi tips

Notes on using mayavi for scientific visualization.

I was having a heck of a time getting mayavi to behave nicely. After much searching, the punchline is:

It looks like the problem had to do with the backend and the key is to add the line

mayavi.ETSConfig.toolkit = 'qt4'

just after importing mayavi.

It is also possible to launch the mayavi application from the terminal like this

ETS_TOOLKIT=qt4 mayavi2

Isosurfaces within mayavi application.

First generate the data. Note - this is done within the iPython terminal embedded *within the mayavi app.

import numpy as np
x, y, z = np.ogrid[-10:10:20j, -10:10:20j, -10:10:20j]
s = np.sin(x*y*z)/(x*y*z)

Then create the visualization object.

import mayavi
from mayavi import mlab
mlab.contour3d(s, contours=5)

In the mayavi application, it is not always clear how to navigate through the various menus. So here are some notes on how to get the multiple transparent isosurfaces we were after.

Click on the IsoSurface in the mayavi “pipeline”. In the “Contours” tab, set the number of contours. In the “Actor” tab, under “Property - more options” you can set “Opacity”. Also here is “Frontface culling” which is useful

Saving an image - clicked disk icon. pdf looks nice, but zooming tends to crash Preview and Skim. png has low resolution - how to improve?

Seems to be better to use

mayavi.mlab.savefig(myfigure.jpg, size=(400,400))

mayavi