【发布时间】:2018-11-10 03:36:22
【问题描述】:
迭代更新非常慢,每次只有 n+=3,但我的数据有 10000 个元素。例如,它尝试更新每一帧 n=1,n=2,n=3.. 但 hist 函数是真的很耗电。我不知道是否有任何方法可以跳过帧,例如从 n=1 直接到 n=500 和 n=1000。
import matplotlib.animation as animation
import numpy as np
import matplotlib.pyplot as plt
n=10000
def update(curr):
if curr==n:
a.event_source.stop()
first_histogram.cla()
sec_histogram.cla()
thi_histogram.cla()
for_histogram.cla()
first_histogram.hist(x1[:curr], bins=np.arange(-6,2,0.5))
sec_histogram.hist(x2[:curr], bins=np.arange(-1,15,1))
thi_histogram.hist(x3[:curr], bins=np.arange(2,22,1))
for_histogram.hist(x4[:curr], bins=np.arange(13,21,1))
first_histogram.set_title('n={}'.format(curr))
fig=plt.figure()
gspec=gridspec.GridSpec(2,2)
first_histogram=plt.subplot(gspec[0,0])
sec_histogram=plt.subplot(gspec[0,1])
thi_histogram=plt.subplot(gspec[1,0])
for_histogram=plt.subplot(gspec[1,1])
a = animation.FuncAnimation(fig,update,blit=True,interval=1,repeat=False)
我怎样才能让它更快?谢谢!
【问题讨论】:
标签: python animation matplotlib