这实际上取决于您如何获取数据,但是:
import matplotlib.pyplot as pltimport numpy as npimport time# create the figurefig = plt.figure()ax = fig.add_subplot(111)im = ax.imshow(np.random.random((50,50)))plt.show(block=False)# draw some data in loopfor 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) tripletsptlist = np.array(ptlist)data[ptlist[:,1].astype('int'), ptlist[:,0].astype('int')] = ptlist[:,2]


