如何在Python中创建热图矩阵并生成基于“热”的区域? [英] How to create a heat map matrix and generate regions based 'heat' in Python?

查看:274
本文介绍了如何在Python中创建热图矩阵并生成基于“热”的区域?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给出一组点(x,y,'热'),

Given a set of points (x, y, 'heat'),

In [15]: df.head()
Out[15]: 
          x         y      heat
0  0.660055  0.395942  2.368304
1  0.126268  0.187978  6.760261
2  0.174857  0.637188  1.025078
3  0.460085  0.759171  2.635334
4  0.689242  0.173868  4.845778

如何生成热图矩阵并界定热区(

这样,给定一个点,就有可能获得同一区域内的所有点。

in such a way that, given a point, it is possible to get all points within the same region.

PS:
来自使用散点数据集在MatPlotLib中生成热图,我知道如何生成区域图,但不知道如何生成区域矩阵(因此,给定一个属性,它表示在哪个区域

PS: From Generate a heatmap in MatPlotLib using a scatter data set, I know how to generate graphs of regions, but not how to generate the region 'matrix' (so that given a property, it says in which region it is).

推荐答案

我想这取决于您如何制作热图,但是assu明您使用链接的帖子中的第一个示例:

I guess it depend how you did the heatmap but assuming you used the first example from the post you linked:

import numpy as np
import numpy.random
import matplotlib.pyplot as plt

# Generate some test data
x = np.random.randn(8873)
y = np.random.randn(8873)

heatmap, xedges, yedges = np.histogram2d(x, y, bins=50)
extent = [xedges[0], xedges[-1], yedges[0], yedges[-1]]

plt.clf()
plt.imshow(heatmap, extent=extent)
plt.show()

现在,如果您对坐标为(a,b)的点有要求,则需要在边距中查找最接近 a 值的位置(我们称其为 a_heatmap )中, b yedges b_heatmap ),然后按以下条件查找返回值:

So you now if you have a request about a point with coords (a,b) you need to find the position of the nearest value to a in xedges (lets call it a_heatmap), the position of the nearest value of b in yedges (b_heatmap), then look for the returned value by :

heatmap[a_heatmap, b_heatmap]

这篇关于如何在Python中创建热图矩阵并生成基于“热”的区域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆