I m trying to generate heatmaps for the some data and my code is shown below:
data = [['basis', 2007, 2008],
[1, 2.2, 3.4],
[2, 0, -2.2],
[3, -4.1, -2.5],
[4, -5.8, 1.2],
[5, -5.4, -3.6],
[6, 1.4, -5.9]]
x_header = data[0][1:]
y_header = [i for i in range(1, 13)]
data=data[1:]
for i in range(len(data)):
data[i] = data[i][1:]
arr = np.array(data)
fig, ax = plt.subplots()
#heatmap = plt.pcolor(arr, cmap = 'RdBu')
norm = MidpointNormalize(midpoint=0)
im = ax.imshow(data, norm=norm, cmap=plt.cm.seismic, interpolation='none')
ax.set_xticks(np.arange(arr.shape[1]), minor=False)
ax.set_yticks(np.arange(arr.shape[0]), minor=False)
ax.xaxis.tick_top()
ax.set_xticklabels(x_header, rotation=90)
ax.set_yticklabels(y_header)
fig.colorbar(im)
plt.show()
It generates the image
I also want to show values inside the grid. Is there any way to do that?