一个动画Mayavi的points3d阴谋 [英] Animating a mayavi points3d plot

查看:683
本文介绍了一个动画Mayavi的points3d阴谋的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使粒子的运动轨迹的视频。然而,不知何故我的场景永远不会更新。这里是一个非常简单的例子:

I'm trying to make a video of the trajectories of particles. However, somehow my scene never updates. Here's a very simple example:

from __future__ import absolute_import, division, print_function
from mayavi import mlab
import numpy as np
import math

alpha = np.linspace(0, 2*math.pi, 100)  

xs = np.cos(alpha)
ys = np.sin(alpha)
zs = np.zeros_like(xs)

mlab.points3d(0,0,0)
plt = mlab.points3d(xs[:1], ys[:1], zs[:1])

@mlab.animate(delay=100)
def anim():
    f = mlab.gcf()
    while True:
        for (x, y, z) in zip(xs, ys, zs):
            print('Updating scene...')
            plt.mlab_source.x[0] = x
            plt.mlab_source.y[0] = y
            plt.mlab_source.z[0] = z
            f.scene.render()
            yield


anim()
mlab.show()

如果我运行此脚本,它显示了两分,动画图形用户界面的窗口。它还会打印的连续流更新场景......消息在终端上。然而,现场根本不表现出任何运动。

If I run this script, it shows a window with the two points and the animation GUI. It also prints a continous stream of "Updating Scene..." messages on the terminal. However, the scene doesn't show any movement at all.

我在做什么错了?

Python 2.7版,4.1 Mayavi的,VTK 5.8

Python 2.7, Mayavi 4.1, VTK 5.8

推荐答案

只需更改为:

...

    for (x, y, z) in zip(xs, ys, zs):
        print('Updating scene...')
        plt.mlab_source.set(x=x, y=y, z=z)
        yield

...

您甚至不需要在 f.scene.render(),根据<一个href=\"http://docs.enthought.com/mayavi/mayavi/mlab_animating.html#mlab-animating-data\">documentation mlab_source.set 保证刷新。

you don't even need the f.scene.render(), according to documentation mlab_source.set guarantees the refresh.

此外,由于您的数据形状不改变你不需要使用 mlab_source.reset

Also since shape of your data doesn't change you don't need to use mlab_source.reset.

我还测试和正常工作。

这篇关于一个动画Mayavi的points3d阴谋的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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