通过clf()处理每个fram,制作matplotlib动画

2024-09-26 22:10:48 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图用animation.FuncAnimation制作最简单的matplotlib动画。我不在乎效率。我不想跟踪绘制的线条和更新它们的数据(在我想要的应用程序中,这会很烦人),我只想在设置每一帧动画之前删除绘图。我以为这样的事情应该有用,但它不是。。在

import matplotlib.animation as animation

fig = Figure()

def updatefig(i):
    clf()
    p = plot(rand(100))
    draw()

anim = animation.FuncAnimation(fig, updatefig, range(10))

Tags: 数据import应用程序绘图matplotlibfig绘制动画
1条回答
网友
1楼 · 发布于 2024-09-26 22:10:48

至少这似乎有效:

import matplotlib.animation as animation
import matplotlib.pyplot as plt
import numpy as np

fig = plt.figure()

def updatefig(i):
    fig.clear()
    p = plt.plot(np.random.random(100))
    plt.draw()

anim = animation.FuncAnimation(fig, updatefig, 10)
anim.save("/tmp/test.mp4", fps=1)

原始代码的问题是Figure用大写的F(应该是figure)写的。在

否则,我建议不要使用pylab样式的“同一名称空间中的所有内容”方法与matplotlib一起使用。另外,使用面向对象的接口而不是plt.drawplt.plot等,将在以后节省大量的麻烦。在

相关问题 更多 >

    热门问题