您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

Python实时变化热图绘图

Python实时变化热图绘图

这实际上取决于您如何获取数据,但是:

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]
python 2022/1/1 18:31:17 有453人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶