Python实时变化热图绘制
我有一个50*50的二维网格。对于每个位置,我都有一个强度值(即数据类似于Python实时变化热图绘制,python,matplotlib,ipython,matplotlib-basemap,Python,Matplotlib,Ipython,Matplotlib Basemap,我有一个50*50的二维网格。对于每个位置,我都有一个强度值(即数据类似于(x,y,强度),用于每个50*50位置)。我想将数据可视化为热图 扭曲的是,每秒钟强度都会发生变化(对于大多数位置),这意味着我需要每秒重新绘制热图。我想知道处理这种实时变化的热图的最佳库/方法是什么。这实际上取决于您如何获取数据,但是: import matplotlib.pyplot as plt import numpy as np import time # create the figure fig = pl
(x,y,强度)
,用于每个50*50位置)。我想将数据可视化为热图
扭曲的是,每秒钟强度都会发生变化(对于大多数位置),这意味着我需要每秒重新绘制热图。我想知道处理这种实时变化的热图的最佳库/方法是什么。这实际上取决于您如何获取数据,但是:
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\u 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]
谢谢你的回答,这确实帮助了我。现在我可以补充一点吗?如果您希望它能够正确更新并以迭代方式显示在您的图形中,您需要在末尾添加一行:
fig.canvas.flush_events()
对于Jupyter用户,要在新窗口中打开图形,请在单元格的开头添加:
%matplotlib qt
您是否有at
ArcGis
?随着ArcGis 10
出现了一个名为arcpy
的Python模块。听起来你可能会发现它有些用处。我们是否可以在热图中添加背景静态图像??