我找到了以下解决方案,可以将行颜色图例添加到 Seaborn 集群图中:
How to express classes on the axis of a heatmap in Seaborn
我有两个相关的问题:
- 如何将图例移动到聚类图的底部?
- 如果表示 row_color 的数据帧的索引有一个名称,它会显示为彩色行下方的标签。如何增加该标签的字体大小?
最佳答案
为了添加颜色图例,首先,您需要创建 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})
关于python-2.7 - 带有图例的 Seaborn clustermap 行颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46201172/