Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Seaborn clustermap row color with legend

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:

  1. how to move the legend to the bottom of the clustermap?
  2. if the index of the dataframe representing row_color has a a name, it appears as a label under the colored row. How to increase the fontsize of that label?
like image 774
Botond Avatar asked Oct 18 '25 18:10

Botond


1 Answers

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})
like image 116
Wubin Ding Avatar answered Oct 21 '25 19:10

Wubin Ding



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!