matplotlib动画速度的问题

时间:2014-11-28 13:04:22

标签: python matplotlib pandas

matplotlib的新手,并尝试通过动画迭代DataFrame来探索现有数据,但似乎很慢,任何人都可以看到我做错了或建议改进,尝试过使用帧速但效果不大我认为它是我的代码,想在15秒内查看这个2000行对象给予或接受。 box是8gb linex所以应该没问题,使用ipython pop out figure来绘制。

from pandas import *
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import animation

coef_mean = DataFrame(np.random.rand(2000,50))
def animate(f_frame):
    plt.cla()
    plt.plot(coef_mean.columns.values, coef_mean.ix[f_frame])
    plt.ylim(f_coef_min,f_coef_max)
fig = plt.figure(figsize=(9,5))
f_coef_min, f_coef_max = coef_mean.min().min()-.02, coef_mean.max().max()+.02
anim = animation.FuncAnimation(fig, animate, frames=150)
plt.show()

那里有什么想法我做错了什么?非常感谢,LW

也可以尝试使用

获取弹出数字
%matplotlib qt

1 个答案:

答案 0 :(得分:2)

您无需在动画功能内重新绘制。相反,您应该只更新绘图的数据。在你的情况下,这样的事情应该有效:

fig, ax = plt.subplots()
custom_plot, = ax.plot(coef_mean.columns.values, coef_mean.ix[0])
ax.set_ylim(f_coef_min,f_coef_max)

def animate(f_frame):
    custom_plot.set_ydata(coef_mean.ix[f_frame])
    return custom_plot,

查看一些动画示例以获取更多信息。例如: http://matplotlib.org/examples/animation/simple_anim.html

相关问题