cyrinepersonne
cyrinepersonne

Reputation: 99

Add annotations to heatmap with python3

I created a heatmap using matplotlib and seaborn, It looks ok.

But my question is how to add values on heatmap. My current heatmap contains only different colors.

import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns

data = pd.DataFrame(data={'x':index, 'y':colonnes, 'z':score})
data = data.pivot(index='x', columns='y', values='z')
sns.heatmap(data)
plt.show()

Any idea please?

Thanks

Upvotes: 1

Views: 163

Answers (1)

Supratim Haldar
Supratim Haldar

Reputation: 2416

sns.heatmap(data, annot=True)

From documentation:

annot : bool or rectangular dataset, optional. If True, write the data value in each cell. If an array-like with the same shape as data, then use this to annotate the heatmap instead of the raw data.

Also, play around with fmt and annot_kws paramaters.

Upvotes: 1

Related Questions