animating with mayavi mlab.points3d

你。 提交于 2020-06-16 18:39:08

问题


Hello everyone i am trying to animate some data using Mayavi mlab.points3d and having some issues. Here is my code:

import numpy as np
from mayavi import mlab

##Some lists to animate
px=np.arange(0,10000,1)
py=np.arange(0,50000,5)

##Animation function
def run(px,py):
        cc = mlab.gcf().scene.camera
        cc.position[-1] = 10
        T_max = len(px)
        delayer=40
        @mlab.animate(delay=delayer)
        def anim_loc():
            f = mlab.gcf()
            while True:
                for i in np.arange(0,T_max,1):
                    s=0.5
                    mlab.points3d(px[i],py[i],s,color=(0,0,0),opacity=1)
                    mlab.view(distance=50,azimuth=80,elevation=80)
                    print(px[i],py[i])
                    yield

        b=anim_loc()
run(px,py)
mlab.show()

When i execute this code the animation only lasts for like 40 frames or so and after that it freezes without any error or exception. When i run the animation multiple times the animation freezes at different frames, sometimes after 20 frames and sometimes even after 80 frames. I am hereby not sure whether it is because of the code i wrote, or the computer i use (which should be fast enough for such task) or it is a bug in Mayavi. I am using spyder 3.2.8 with anaconda navigator. I would be very pleased for any help :).


回答1:


You have to change the data in the sources in your @mlab.animated function. You're calling the plotter function instead.

Here's a reduced version of your example:

import numpy
from mayavi import mlab


# data
px=numpy.arange(0,10000,1)
py=numpy.arange(0,50000,5)
pz=numpy.zeros_like(px)
s=0.5
# render
pts=mlab.points3d(px,py,pz)
T_max = len(px)
delayer=40
@mlab.animate(delay=delayer)
def anim_loc():
    for i in numpy.arange(2, T_max,500):
        _x = px[0:i]
        _y = px[0:i]
        _z = pz[0:i]
        pts.mlab_source.reset( x = _x, y = _y, z = _z, )
        yield

anim_loc()
mlab.show()


来源:https://stackoverflow.com/questions/51965111/animating-with-mayavi-mlab-points3d

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!