Custom Annotation Seaborn Heatmap

This feature has just been added in the recent version of Seaborn 0.7.1.

From Seaborn update history:

The annot parameter of heatmap() now accepts a rectangular dataset in addition to a boolean value. If a dataset is passed, its values will be used for the annotations, while the main dataset will be used for the heatmap cell colors

Here is an example

data = np.array([[0.000000,0.000000],[-0.231049,0.000000],[-0.231049,0.000000]])
labels =  np.array([['A','B'],['C','D'],['E','F']])
fig, ax = plt.subplots()
ax = sns.heatmap(data, annot = labels, fmt="")

Note, fmt=”” is necessary if you are using non-numeric labels, since the default value is fmt=”.2g” which makes sense only for numeric values and would lead to an error for text labels.
enter image description here

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)