使用mayavi mlab.points3d制作动画 [英] animating with mayavi mlab.points3d

查看:272
本文介绍了使用mayavi mlab.points3d制作动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我正在尝试使用Mayavi mlab.points3d制作一些数据的动画,并遇到一些问题。这是我的代码:

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()

当我执行此代码时,动画仅持续约40帧左右,此后f没有任何错误或异常。当我多次运行动画时,动画冻结在不同的帧上,有时在20帧之后,有时甚至在80帧之后。在此我不确定这是因为我编写的代码,还是因为我使用的计算机(对于这样的任务应该足够快)还是Mayavi中的错误。我将spyder 3.2.8与anaconda导航器一起使用。我会很高兴为您提供帮助:)。

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

推荐答案

您必须在<$ c中更改源中的数据$ c> @ mlab.animate d函数。

这里是示例的简化版本:

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()

这篇关于使用mayavi mlab.points3d制作动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆