python - 具有两个 row_colors 的 Seaborn clustermap

标签 python cluster-analysis seaborn

简单的问题,我有一个在 row_colors 中包含变量“age_range”的聚类图,我也想将变量“education”添加为 row_color。我有以下工作代码:

agerange = df_cor_small.pop("agerange")
lut = dict(zip(agerange.unique(), "rbg"))
row_colors = agerange.map(lut)

ax = sns.clustermap(df_cor_small, cmap='YlGnBu', row_colors=row_colors, figsize=(15,100), cbar_pos=(1.05, .2, .03, .4))

输出这个数字: enter image description here

(目前 df_cor_small 不包含变量“education”,但一旦我知道如何实现它,它就会包含在内,因此它将像“agerange”一样可弹出)

有什么建议我可以实现这个吗?

最佳答案

您可以将颜色作为数据框提供,我认为您现在正在提供一个列表。在下面的示例中,我将黑色分配给 8 种颜色,将 7x20 分配给行,将 10 分配给行。没有对行进行聚类来显示分配是正确的:

import seaborn as sns; sns.set(color_codes=True)
import string
iris = sns.load_dataset("iris")
species = iris.pop("species")
lut = dict(zip(species.unique(), "rbg"))
samples = np.repeat(list(string.ascii_letters[0:8]),20)[:150]
sample_cols = dict(zip(set(samples), sns.color_palette("cubehelix", 8)))

row_colors = pd.DataFrame({'species':species.map(lut),
                          'sample':[sample_cols[i] for i in samples]})
g = sns.clustermap(iris, row_colors=row_colors,row_cluster=False)

enter image description here

关于python - 具有两个 row_colors 的 Seaborn clustermap,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61816216/

相关文章:

python - 在 Seaborn 中向热图注释添加单位

python - 我可以在排序列表时使 python 代码工作吗

python - “numpy.float64”对象不可迭代 - 均值漂移聚类

python - 如何更改seabornpairplot中x或y标签的字体大小?

python - 如何使用 Y 轴值将坐标值聚集到行中?

machine-learning - 什么方法最适合对形状不规则的多维数据进行聚类?

python - 将两个用户定义函数中的 ax 和 fig 合并到一个图中?

python - 单用户应用程序可以使用 Django 开发服务器吗?

python - Mac 上的 wxpython - 按钮样式

python - 无法导入 'django.http' pylint(导入错误)