Why this Mayavi animation stops executing at a random iteration?

160 views Asked by At

I read a few questions similar to mine but none of the answers work... I want to make an animation that plots the points of a list one by one. The problem is that from rank 12, it stops. I tested gc.collect(generation=1) but it didn't work... Here is the end of my code :

@mlab.animate(delay=100)
def updateAnimation():
   k=0
   for k in range(len(X)):
      mlab.points3d(X[k], Y[k], Z[k], S[k], color=C[k], scale_factor=10)
      yield

updateAnimation()
mlab.show()

X, Y, Z, S and C are lists with a length of 136. I am using python 3.9.12 and mayavi 4.8.0. It's maybe something stupid with set... but I'm new at mayavi.

Thank you very much for any insight.

1

There are 1 answers

1
MAS On
p3d = mlab.points3d(X[0], Y[0], Z[0], S[0], color=C[0], scale_factor=10)

@mlab.animate(delay=100)
def updateAnimation():
   k=0
   for k in range(len(X)):
      p3d.set(x=X[k], y=Y[k], z=Z[k], s=S[k], color=C[k])
      yield

ua = updateAnimation()
mlab.show()

`

This (untested code) is prettymuch a copy from here http://docs.enthought.com/mayavi/mayavi/mlab.html#id10

You create the visualization once and update it in the updateAnimation procedure. The ua = updateAnimation() stores the result in a variable so that the animation keeps running even if it is called from an asynchronous coroutine. You use set() if the shape of your data remains the same and reset() otherwise. This works with point3d and plot3d but unfortunately not with all plots in mlab.