Animation 延时动画

Animation 延时动画,animation,matplotlib,Animation,Matplotlib,我不熟悉python、matplotlib和动画。 我还没能找到一个清晰、详细的描述 animation.FuncAnimation(,,…),所以我一直在尝试修改我找到的示例。英文版的FuncAnimation的所有允许参数是什么 我想制作一个点的图形,每次显示一个点,两次显示之间的时间间隔约为1秒 下面是我当前的代码,它只在延迟后生成一条连续曲线: def init(): line1.set_data([],[],'og') return line1, def animat

我不熟悉python、matplotlib和动画。 我还没能找到一个清晰、详细的描述
animation.FuncAnimation(,,…)
,所以我一直在尝试修改我找到的示例。英文版的
FuncAnimation
的所有允许参数是什么

我想制作一个点的图形,每次显示一个点,两次显示之间的时间间隔约为1秒

下面是我当前的代码,它只在延迟后生成一条连续曲线:

def init():
    line1.set_data([],[],'og')
    return line1,

def animate(x):
    x = np.linspace(0, 650, num=20, endpoint = True)  #start at 0, stop at 650, number of values
    y1 = (v0_y/v0_x)*x - (g/2)*(x/v0_x)**2
    line1.set_data(x, y1)
    time.sleep(1)
    return line1,

anim = animation.FuncAnimation(fig, animate, init_func=init, frames=100, interval=3000, blit=True)

感谢所有建议

您可以查看
FuncAnimation
的文档,这是一个示例代码,可以满足您的需要:

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

xs = np.linspace(0, 650, num=20, endpoint = True)
ys = np.random.rand(20)

fig = plt.figure()
line1, = plt.plot([],[],'og')

plt.gca().set_xlim(0,650)

def init():
    return line1,

def animate(i):

    line1.set_data(xs[:i], ys[:i])
    return line1,

anim = animation.FuncAnimation(fig, animate, init_func=init, interval=1000, blit=True)
plt.show()
输出窗口:


我非常感谢您的回复。但是,当我运行这个示例时,它只绘制了2个点。每次运行时,它只绘制两个不同的点。我认为应该画20个随机点。我仍然不理解animation.FuncAnimation-引用的文档太简洁了!我今天刚刚复制粘贴了代码,运行之后,我在答案上发布了(刚刚添加的)图像。这些点一个接一个地显示到最后。