Create Point Cloud / Label Points
If you are using MayaVi 1.3 or from CVS you can also label points from a script like so
#! /usr/bin/python
# example of mayavi point cloud plot with data labels
# run from idle or with -i option set at python command line
# mayavi v1.3 or from CVS.
# pyvtk v0.4.62
# vtk >= v4.0
import mayavi
from Numeric import *
from pyvtk import *
def func(x,y):
a=sin(x)
b=cos(y)
c=a*b
return a,b,c
a,b,c = func(arange(0,2*pi,.1),arange(0,2*pi,.1))
# create vtk file from function
nodes = transpose([a]+[b]+[c])
vt = VtkData(UnstructuredGrid(nodes, vertex=range(len(a))),
PointData(Scalars(c)),
'Point Cloud')
vt.tofile('xyz.vtk')
# display data
v = mayavi.mayavi()
d = v.open_vtk('xyz.vtk', 0)
m = v.load_module('SurfaceMap', 0)
m.act.GetProperty().SetPointSize(7)
a = v.load_module('Axes',0)
a.axes.SetCornerOffset(0.0)
# now label the first actor (index == 0)
# note the third and fourth arguments to the following function call.
m = v.load_module('Labels', 0, module=0, n_points=50)
m.mapper.SetLabelModeToLabelIds()
If you're like me and enjoy playing with the MayaVi window after a piece of Python "code-behind" has executed, then you may like to stop the window disappearing right away. Simply add:
v.master.wait_window()
to the end of the code, and the window will remain after the preceding Python code has executed, leaving you with a full MayaVi session.
MayaVi Wiki