【问题标题】:Changing number of points in mayavi animation更改 mayavi 动画中的点数
【发布时间】:2019-03-05 15:43:09
【问题描述】:

这是 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.clf() 之后简单地重新绘制mlab.points3d(x, y, z),但动画没有显示——只显示最后一帧。

提前谢谢你。

【问题讨论】:

    标签: python plot mayavi


    【解决方案1】:

    根据the docs,您应该使用reset() 而不是set()

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

    【讨论】:

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