这是Python Mayavi中的简单动画脚本:
from mayavi import mlab
import numpy as np
alpha = np.linspace(0, 2*np.pi, 100)
beta = np.linspace(0, np.pi, 100)
x = np.sin(beta) * np.cos(alpha)
y = np.sin(beta) * np.sin(alpha)
z = np.cos(beta)
plt = mlab.points3d(x, y, z)
@mlab.animate(delay=100)
def anim():
global x, y, z
f = mlab.gcf()
for _ in range(100):
# x = np.concatenate((x, [np.random.random()]))
# y = np.concatenate((y, [np.random.random()]))
# z = np.concatenate((z, [np.random.random()]))
x = 1.1 * x
plt.mlab_source.set(x=x, y=y, z=z)
f.scene.render()
yield
anim()
mlab.show()
运行良好,积分四处移动。但是,我想取消注释np.concatenate
线,以便在动画期间点数变化...... Mayavi似乎不支持这个?
我认为这种限制与更新情节的效率有关,但我希望以上工作并且不介意任何速度命中。
有任何想法吗?
我试过在mlab.points3d(x, y, z)
之后简单地重新绘制mlab.clf()
,但是动画没有显示 - 只有最后一帧。
先感谢您。
你应该使用reset()
而不是set()
每the docs:
x, y = np.mgrid[0:3:1,0:3:1]
s = mlab.surf(x, y, np.asarray(x*0.1, 'd'),
representation='wireframe')
# Animate the data.
fig = mlab.gcf()
ms = s.mlab_source
for i in range(5):
x, y = np.mgrid[0:3:1.0/(i+2),0:3:1.0/(i+2)]
sc = np.asarray(x*x*0.05*(i+1), 'd')
ms.reset(x=x, y=y, scalars=sc)
fig.scene.reset_zoom()