How To Create A Heat Map Matrix And Generate Regions Based 'heat' In Python?
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.6
Solution 1:
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()
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]
Post a Comment for "How To Create A Heat Map Matrix And Generate Regions Based 'heat' In Python?"