2016-01-20 88 views
0

给定一组点(X,Y, '热')的,如何在Python中创建热图矩阵并生成基于'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 

如何产生的热图矩阵和限定热区(硬)?

以这样的方式,给定一个点,可以获得同一区域内的所有点。

PS: 从Generate a heatmap in MatPlotLib using a scatter data set,我知道如何生成区域的图形,但不知道如何生成区域'矩阵'(以便赋予一个属性,它说明它在哪个区域)。

回答

0

我想这取决于你是怎么做到的热图,但假设你用从后您链接的第一个例子:

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() 

所以,你现在如果你有一个关于与COORDS点数请求(a,b)你需要找到xedges最接近值a的位置(让叫它a_heatmap)的b最接近值的yedgesb_heatmap)的位置,然后查找返回的值是:

heatmap[a_heatmap, b_heatmap] 
+0

这几乎是我正在寻找的......但让我们假设测试点'(a,b)'所在的区域是区域[5,5] ...但该区域可能由[5,5],[5,6],[5,7],[6,5],[6.7] ...都具有几乎相同的平均“热量”。 如何自动“合并”区域以获得“更广泛”的区域? –