我找到了以下解决方案,为Seaborn群集图添加行颜色图例:
How to express classes on the axis of a heatmap in Seaborn
我有两个相关的问题:
答案 0 :(得分:3)
要添加颜色图例,首先需要创建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]
然后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})