【问题标题】:mayavi points3d plot animation won't update the next framemayavi points3d 绘图动画不会更新下一帧
【发布时间】:2014-07-24 16:23:14
【问题描述】:

我正在编写一段代码,可视化四个字形在空间中移动。目前 mayavi 窗口显示初始位置,但不会更新到下一个位置。

    #Library decleration 
import numpy as np
from mayavi.mlab import *

....

#Inputting the intital positions into the storage vector
storage_position[0].append(v_1.theta)
storage_position[1].append(v_1.phi)
#Calculating the rest of the positions using the symmetry given
storage_position = Sym(storage_position)

#Plotting the intitial positions 

x_coord = x_trans( storage_position)
y_coord = y_trans(storage_position)
z_coord = z_trans( storage_position)


plt = points3d(x_coord, y_coord, z_coord)

msplt = plt.mlab_source
@mlab.animate(delay=100)
def anim(storage_position, storage_vort, no_vort ,x_coord, y_coord, z_coord):
    f = mlab.gcf()
    while True:
    #for i in range(10):      
        #Working out the hamiltonian
        #Hami(storage_position, storage_vort, 1 - 1, no_vort-1)

        transfer_vector = method(storage_position, storage_vort, 1 - 1, no_vort-1)
        storage_position[0].append(transfer_vector[0])
        storage_position[1].append(transfer_vector[1])
        storage_position = Sym(storage_position)


        x_coord = x_trans( storage_position)
        y_coord = y_trans(storage_position)
        z_coord = z_trans( storage_position)

        msplt.set(x_coord = x_coord, y_coord = y_coord, z_coord = z_coord)

        yield


anim(storage_position, storage_vort, no_vort - 1,x_coord, y_coord, z_coord)
mlab.show()

x_coord 等是存储四个字形的 x 坐标的 numpy 向量。 x_trans 等是使用动画每一步的新坐标更新每个向量的函数。

【问题讨论】:

  • 能否给出一个完整的可执行示例?上面的代码没有定义x_trans

标签: python python-2.7 animation numpy mayavi


【解决方案1】:

尝试替换这一行:

msplt.set(x_coord = x_coord, y_coord = y_coord, z_coord = z_coord)

用这个:

msplt.set(x=x_coord, y=y_coord, z=z_coord)

点集数据源(应该是MGlyphSource类型的对象)知道xyz,但不支持x_coordy_coordz_coord作为关键字参数。

这是一个完整的工作示例,可帮助您入门:

from mayavi import mlab
from numpy import array, cos, sin, cos

x_coord = array([0.0, 1.0, 0.0, -1.0])
y_coord = array([1.0, 0.0, -1.0, 0.0])
z_coord = array([0.2, -0.2, 0.2, -0.2])

plt = mlab.points3d(x_coord, y_coord, z_coord)

msplt = plt.mlab_source
@mlab.animate(delay=100)
def anim():
    angle = 0.0
    while True:
        x_coord = array([sin(angle), cos(angle), -sin(angle), -cos(angle)])
        y_coord = array([cos(angle), -sin(angle), -cos(angle), sin(angle)])
        msplt.set(x=x_coord, y=y_coord)
        yield
        angle += 0.1

anim()
mlab.show()

请注意,当您运行此程序时,您可能会看到很多警告打印到控制台。忽略它们:它们是无害的,并且是known issue

【讨论】:

    猜你喜欢
    • 2012-12-26
    • 2014-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多