这实际上取决于您如何获取数据,但是:
import matplotlib.pyplot as plt
import numpy as np
import time
# create the figure
fig = plt.figure()
ax = fig.add_subplot(111)
im = ax.imshow(np.random.random((50,50)))
plt.show(block=False)
# draw some data in loop
for i in range(10):
# wait for a second
time.sleep(1)
# replace the image contents
im.set_array(np.random.random((50,50)))
# redraw the figure
fig.canvas.draw()
这应该以1秒的间隔绘制11张随机的50x50图像。基本部分是im.set_array
替换图像数据并将fig.canvas.draw
图像重新绘制到画布上。
如果您的数据确实是表单中的点列表(x, y, intensity)
,则可以将它们转换为numpy.array
:
import numpy as np
# create an empty array (NaNs will be drawn transparent)
data = np.empty((50,50))
data[:,:] = np.nan
# ptlist is a list of (x, y, intensity) triplets
ptlist = np.array(ptlist)
data[ptlist[:,1].astype('int'), ptlist[:,0].astype('int')] = ptlist[:,2]