Mayavi surf

Date:2007-02-20 (last modified), 2006-12-04 (created)

If you want to plot a surface representing a matrix by elevation and colour of its points you have to transform the matrix data in a 3D data that !MayaVi2 can understand. [:Cookbook/MayaVi/mlab:mlab] knows how to do this, but it does not have the nice user interface of !MayaVi2. Here is a script that create a !SurfRegular object using mlab, and then loads it in !MayaVi2. A more detailed version of this script is given in the examples pages [:Cookbook/MayaVi/Examples].

In [ ]:
import numpy
def f(x, y):
    return numpy.sin(x*y)/(x*y)
x = numpy.arange(-7., 7.05, 0.1)
y = numpy.arange(-5., 5.05, 0.05)
from import mlab
s = mlab.SurfRegular(x, y, f)
from enthought.mayavi.sources.vtk_data_source import VTKDataSource
d = VTKDataSource() =
from enthought.mayavi.filters.warp_scalar import WarpScalar
w = WarpScalar()
from enthought.mayavi.modules.outline import Outline
from enthought.mayavi.modules.surface import Surface
o = Outline()
s = Surface()

You can run this script by running "mayavi2 -n -x", loading it through the menu (File -> Open File), and pressing Ctrl+R, or entering "execfile('') in the python shell.

Section author: GaelVaroquaux, Unknown[41], Unknown[132]