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. 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.

   1 import numpy
   2 def f(x, y):
   3     return numpy.sin(x*y)/(x*y)
   4 x = numpy.arange(-7., 7.05, 0.1)
   5 y = numpy.arange(-5., 5.05, 0.05)
   6 from enthought.tvtk.tools import mlab
   7 s = mlab.SurfRegular(x, y, f)
   8 from enthought.mayavi.sources.vtk_data_source import VTKDataSource
   9 d = VTKDataSource()
  10 d.data = s.data
  11 mayavi.add_source(d)
  12 from enthought.mayavi.filters.warp_scalar import WarpScalar
  13 w = WarpScalar()
  14 mayavi.add_filter(w)
  15 from enthought.mayavi.modules.outline import Outline
  16 from enthought.mayavi.modules.surface import Surface
  17 o = Outline()
  18 s = Surface()
  19 mayavi.add_module(o)
  20 mayavi.add_module(s)

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

Cookbook/MayaVi/Surf (last edited 2007-02-20 06:56:08 by GaelVaroquaux)