updating color of 3D points during animation

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

updating color of 3D points during animation

This post has NOT been accepted by the mailing list yet.
Hi All,

As a start of a project I wish to build networks and animate them in such a way that the nodes change color dynamically depending on a scalar. To do so I am trying to run a basic script in which I try to change the color of points during an animation. My code is the following:

from mayavi import mlab
import numpy as np

# create some data
x=np.array([0,0,0,0,1,1,1,1]) # poistion along x
y=np.array([0,0,1,1,0,0,1,1]) # position along y
z=np.array([0,1,0,1,0,1,0,1]) # position along z
s=np.array([.5,.6,.7,.8,.8,.7,.6,.5]) # size

# visualize as points
pts=mlab.points3d(x,y,z,t,scale_factor=.5, colormap='cool', mode='sphere', scale_mode='none', vmin=0, vmax=10)

# animate the data
@mlab.animate(delay=100, ui=True)
def anim():
    print 'start animation'
    while True:
        for i in range(10):
            t=np.array([i,i,i,i,i,i,i,i]) # where the array controlling the color is updated
            ms.set(t=t) # update the data
            print 'set'


The animation runs, but the color of the points is not changed. I have tried by updating the x array and in that case the position is changing, but not with colors. I am probably missing something silly, but I cannot figure it out. Does anyone have an idea on what I am doing wrong?