Mayavi 4.6 easy install

Mayavi 4.6 and VTK 8 use QT5 and are pip (or conda) installable, which makes the install process much easier than before. VTK, Traits, et al now have .whl wheels, which avoid the previously painful build process. Install Mayavi simply by:

python -m pip install mayavi

You may get spurious error during install, disregard it.

ModuleNotFoundError: No module named ‘vtk’

Plot 3-D data

Using Mayavi, Matplotlib or more advanced modules, one can make very high quality, manipulable volume plots. Create a file scalar_field.py with the content

from mayavi import mlab
import numpy as np

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

mlab.pipeline.volume(mlab.pipeline.scalar_field(x,y,z,s))
mlab.show()

test program for Mayavi

from mayavi import mlab

mlab.show()

should not error.

Test programs for Mayavi. Mayavi should not error with

ImportError: Could not import backend for traits

Notes

Mayavi plots not displaying

If you’re running on Linux or Windows Subsystem for Linux you need to have an X11 server or Wayland server running (including on WSL).