2016-01-20 35 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] ...都具有幾乎相同的平均「熱量」。 如何自動「合併」區域以獲得「更廣泛」的區域? –