【发布时间】:2020-06-28 19:54:11
【问题描述】:
对于一个个人项目,我正在尝试对一个相当大的数据集(1000 行)进行动画处理,以在 Jupyter 笔记本中显示多次鸟类潜水。最后,我还想添加加速度数据的子图。
我用简单的例子作为粗略的模板,比如:https://towardsdatascience.com/animations-with-matplotlib-d96375c5442c中的成长线圈例子
代码本身似乎运行缓慢但很好,但它不输出动画,只是一个静态图:
这是我当前的代码:
x = np.array(dives.index)
y = np.array(dives['depth'])
x_data, y_data = [], []
fig = plt.figure()
ax = plt.axes(xlim=(0, 1000), ylim=(min(y),max(y)))
line, = ax.plot([], [])
def init():
line.set_data([], [])
return line,
def animate(i):
x_data.append(x[i])
y_data.append(y[i])
line.set_data(x, y)
return line,
plt.title('Bird Dives')
ani = animation.FuncAnimation(
fig, animate, init_func=init, frames= 1000, interval=50, blit=True)
ani.save('./plot-test.gif')
plt.show()
它只是绘制图形而不是动画图形有什么原因吗?
【问题讨论】:
标签: python matplotlib animation jupyter-notebook visualization