The annotation function defines how to draw the graphics at a certain position corresponding to the column or row in the heatmap.
There is no automatic feature to do such a thing, but you could loop through each point and put text in the appropriate location:
import matplotlib.pyplot as plt
import numpy as np
data = np.random.rand(5, 4)
heatmap = plt.pcolor(data)
for y in range(data.shape[0]):
for x in range(data.shape[1]):
plt.text(x + 0.5, y + 0.5, '%.4f' % data[y, x],
horizontalalignment='center',
verticalalignment='center',
)
plt.colorbar(heatmap)
plt.show()
HTH
The seaborn heatmap does the job automatically, by setting annot=True
.
See this for an example.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With