I found the following solution to add a row color legend to a Seaborn clustermap:
How to express classes on the axis of a heatmap in Seaborn
I have two related questions:
In order to add color legend, first, you need to create legend_TN .
import matplotlib.patches as mpatches
import seaborn as sns
legend_TN = [mpatches.Patch(color=c, label=l) for c,l in df[['tissue type','label']].drop_duplicates().values]
then g=sns.clustermap(...)
l2=g.ax_heatmap.legend(loc='center left',bbox_to_anchor=(1.01,0.85),handles=legend_TN,frameon=True)
l2.set_title(title='tissue type',prop={'size':10})
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