我需要动画数据,因为它们带有2D histogram2d(也许后来3D,但我听说mayavi更好)。Matplotlib动画速度太慢(〜3 fps)
下面的代码:
import numpy as np
import numpy.random
import matplotlib.pyplot as plt
import time, matplotlib
plt.ion()
# Generate some test data
x = np.random.randn(50)
y = np.random.randn(50)
heatmap, xedges, yedges = np.histogram2d(x, y, bins=5)
extent = [xedges[0], xedges[-1], yedges[0], yedges[-1]]
# start counting for FPS
tstart = time.time()
for i in range(10):
x = np.random.randn(50)
y = np.random.randn(50)
heatmap, xedges, yedges = np.histogram2d(x, y, bins=5)
plt.clf()
plt.imshow(heatmap, extent=extent)
plt.draw()
# calculate and print FPS
print 'FPS:' , 20/(time.time()-tstart)
它返回3 fps的,太慢明显。是否在每次迭代中使用numpy.random?我应该使用blit吗?如果是这样如何?
该文档有一些很好的例子,但对我来说,我需要了解一切。
非常感谢@Chris我找到了适合我的解决方案。 matplotlib文档非常全面,但示例可以使用一些文档。再次,谢谢:) – storedope