Seaborn clustermap 有两个 row_colors
Seaborn clustermap with two row_colors
快速提问,我在 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))
输出这个数字:
(目前 df_cor_small 不包含变量 'education' 但一旦我知道如何实现它就会包含它,所以它将像 'agerange' 一样可弹出)
有什么建议可以实现吗?
您可以将颜色作为 data.frame 提供,我想您现在正在提供一个列表。在下面的示例中,我将黑色分配给 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)
快速提问,我在 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))
输出这个数字:
(目前 df_cor_small 不包含变量 'education' 但一旦我知道如何实现它就会包含它,所以它将像 'agerange' 一样可弹出)
有什么建议可以实现吗?
您可以将颜色作为 data.frame 提供,我想您现在正在提供一个列表。在下面的示例中,我将黑色分配给 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)