按组划分的齿形图着色

问题描述 投票:0回答:1

我使用seaborn clustermap作为以下对象,基于spearman的相关矩阵创建了一个热图:

sns.set(font_scale=1)
g = sns.clustermap(df, cmap="bwr",
                   vmin=-1, vmax=1,
                   yticklabels=1, xticklabels=1,
                   cbar_kws={"ticks":[-1,-0.5,0,0.5,1]},
                   figsize=(13,13),
                   row_colors=row_colors,
                   col_colors=col_colors,
                   method='average',
                   metric='correlation')
g.ax_heatmap.set_xlabel('Genus')
g.ax_heatmap.set_ylabel('Genus')
for l in g.ax_row_dendrogram.collections:
        l.set_color((sns.color_palette("hls", 2)))
for l in g.ax_col_dendrogram.collections:
        l.set_color((sns.color_palette("hls", 5)))

而我得到了这个情节:heatmap

您可以看到,颜色是随机的,没有按组划分。我希望它看起来像这样:dendrogram

在此方面的任何帮助将不胜感激!Tnx!

python seaborn hierarchical-clustering dendrogram
1个回答
0
投票

根据sns.clustermap文档,可以通过sns.clustermap(采用字典)及其期望具有RGB元组列表(例如tree_kws)的colors属性来设置树状图着色。

我希望这会有所帮助!

© www.soinside.com 2019 - 2024. All rights reserved.