Matplotlib animate 似乎没有 运行 功能?
Matplotlib animate doesn't appear to run function?
我正在尝试创建一个动画线图的图。我很高兴地创建了相同数据的静态版本,但我所做的一切都没有创建动画图。我有一个数据框可以 df_output 包含日期作为索引和数据本身的不同列。我试过这个,它只是在 Jupyter 中创建了一个不更新的空图:
%matplotlib notebook
import matplotlib.animation as animation
def animate(i, data_lst):
data_lst.append(df_output.iloc[i,1])
ax.clear()
ax.plot(data_lst)
ax.set_ylim(0, max(data_lst))
ax.set_title('Test title')
ax.set_ylabel('Test label')
data_lst = []
fig, ax = plt.subplots()
ani = animation.FuncAnimation(fig, animate, frames=100, fargs=(data_lst), interval=100)
plt.show()
我是不是遗漏了什么明显的东西?我在 Spyder 中尝试了代码,它暗示我实际上并没有调用 matplotlib.animation 库?谢谢!
是的,这有点有趣,但是 ([])
不是单长元组,([],)
是。在上面替换 fargs=(data_lst,)
是让它工作所需的全部。或者只使用 fargs=[data_lst]
而不是元组。
我正在尝试创建一个动画线图的图。我很高兴地创建了相同数据的静态版本,但我所做的一切都没有创建动画图。我有一个数据框可以 df_output 包含日期作为索引和数据本身的不同列。我试过这个,它只是在 Jupyter 中创建了一个不更新的空图:
%matplotlib notebook
import matplotlib.animation as animation
def animate(i, data_lst):
data_lst.append(df_output.iloc[i,1])
ax.clear()
ax.plot(data_lst)
ax.set_ylim(0, max(data_lst))
ax.set_title('Test title')
ax.set_ylabel('Test label')
data_lst = []
fig, ax = plt.subplots()
ani = animation.FuncAnimation(fig, animate, frames=100, fargs=(data_lst), interval=100)
plt.show()
我是不是遗漏了什么明显的东西?我在 Spyder 中尝试了代码,它暗示我实际上并没有调用 matplotlib.animation 库?谢谢!
是的,这有点有趣,但是 ([])
不是单长元组,([],)
是。在上面替换 fargs=(data_lst,)
是让它工作所需的全部。或者只使用 fargs=[data_lst]
而不是元组。