我需要動畫數據,因爲它們帶有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