2014-07-24 38 views
2

我正在寫一個代碼,通過空間移動的四個字形的可視化。目前mayavi窗口顯示了初始位置,但不會更新到下一個位置。mayavi points3d情節動畫將不會更新下一幀

#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等是numpy矢量,它存儲四個字形的x座標。 x_trans等是用每個步驟的新座標更新每個向量的函數。

+0

你能舉一個完整的可執行示例嗎?上面的代碼沒有定義'x_trans'。 –

回答

2

試圖替換這一行:

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