Reading the data into numpy arrays. Not the most efficient or correct way to do it but it does the job.
def get_data():
fin=open(r"C:\Users\yoavram\Downloads\tile1.csv")
x,y,z=[],[],[]
for line in fin:
values = line.strip().split(',')
z.append(float(values[2]))
fin.close()
z = array(z)
z = z.reshape( (100,100) )
z = np.rot90(z)
return z
Now I'm gonna try to do a heatmap with interpolation.
These are the interpolations available for pyplot.imshow
:
interpolations = ['none', 'nearest', 'bilinear',
'bicubic', 'spline16', 'spline36', 'hanning', 'hamming',
'hermite', 'kaiser', 'quadric', 'catrom', 'gaussian',
'bessel', 'mitchell', 'sinc', 'lanczos']
This simple function will create a 8x8 figure of the z data:
def heatmap(data, interpolation):
fig = plt.figure(figsize=(8,8))
ax = fig.add_subplot(111)
ax.imshow(data, interpolation=interpolation)
ax.set_title(interpolation)
And now to plot with each interpolation:
z = get_data()
for i in interpolations:
heatmap(z, i);
Now to use the heatmap.py package:
The data given to this package is simply points - it overlays them and the coloring is by the amount of points at each position. So I need to change the data:
z = get_data()
points = []
for i in range(100):
for j in range(100):
p = z[i,j] + 1
if not isnan(p):
for k in range(int(p)):
points.append( (i,j) )
After converting the data I can create an image of the heatmap:
import heatmap
hm = heatmap.Heatmap()
#img = hm.heatmap([(random.random(), random.random()) for x in range(100)], scheme="fire")
img = hm.heatmap(points, scheme="fire")
plt.imshow(np.asarray(img));