3

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?
Botond
  • 2,640
  • 6
  • 28
  • 44

1 Answers1

4

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})
Odin
  • 1,914
  • 10
  • 5
  • This allowed me to create a legend for the side bars. Any idea how to move the legend at the bottom (or right, or whatever)? `clustermap` provides `cbar_kws` for doing that, but I keep getting errors if I use that argument – mic Aug 29 '18 at 22:27