Jake Vanderplas的教程中的这个例子可能是
matplotlib动画:from __future__ import division
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
def init():
return [line]
def animate(i, ax, line):
x = np.linspace(0, 2*np.pi, N) + i/(N*2)
ax.set_xlim(x.min(), x.max())
line.set_data(x, np.sin(x))
return [line]
N = 100
fig, ax = plt.subplots()
line, = ax.plot([], [])
ax.set_xlim(0, 2*np.pi)
ax.set_ylim(-1, 1)
ani = animation.FuncAnimation(
fig, animate, init_func=init, interval=0, frames=int(4*np.pi*N),
repeat=True, blit=True, fargs=[ax, line])
plt.show()
更改不同的值或代码行,看看会发生什么。看看如果
{cd1>换点别的。如果你学习和玩这些
举例来说,你可以学习这些部分是如何组合在一起的。在
一旦你理解了这个例子,你应该能够修改它来适应你的
目标。在
如果有问题,请发布代码并描述错误消息或
你看,行为不端。在
一些提示:因为动画需要调用line.set_data,所以我不认为你
可以使用熊猫的df.plot()。事实上,我不确定熊猫数据帧是否
这里有用。最好将数据吸入列表或NumPy数组中
像上面一样把它们传给{},而不让熊猫参与。
打开到数据库的连接应该完成一次。animate得到
打了很多次电话。所以最好定义conn和c和query任何不随animate调用而改变的内容
在animate之外,并通过
fargs参数。