在sns.clustermap中为color_row添加更多空间

时间:2018-05-17 16:13:25

标签: matplotlib seaborn

如何为column / row_colors添加更多间距?在添加3行或更多行后,它看起来非常密集

#modified example data is from this question: https://stackoverflow.com/questions/48173798/additional-row-colors-in-seaborn-cluster-map

matrix = pd.DataFrame(np.random.random_integers(0,1, size=(50,4)))

labels = np.random.random_integers(0,5, size=50)
lut = dict(zip(set(labels), sns.hls_palette(len(set(labels)), l=0.5, s=0.8)))

row_colors = pd.DataFrame(labels)[0].map(lut)

#Create additional row_colors here
labels2 = np.random.random_integers(0,1, size=50)
lut2 = dict(zip(set(labels2), sns.hls_palette(len(set(labels2)), l=0.5, s=0.8)))
row_colors2 = pd.DataFrame(labels2)[0].map(lut2)

# add more rows
row_colors = pd.concat([row_colors,row_colors,row_colors2,row_colors2,row_colors2],axis=1)

g=sns.clustermap(matrix, col_cluster=False, linewidths=0.1, cmap='coolwarm', row_colors=row_colors)
plt.show()

cluster_example

1 个答案:

答案 0 :(得分:0)

您可以调整for(id in 1:nrow(df2)){ Xfind<-df$Role_Primary[df$uniqueID %in% df2$uniqueID[id]] if (any(Xfind=="X")){df2$Role_Primary[id]<-"X"} Xfind2<-df$Role_Signatory[df$uniqueID %in% df2$uniqueID[id]] if (any(Xfind2=="X")){df2$Role_Signatory[id]<-"X"} Xfind3<-df$Role_Comms[df$uniqueID %in% df2$uniqueID[id]] if (any(Xfind3=="X")){df2$Role_Comms[id]<-"X"} } 参数。

df2 会给你更多的间距。

enter image description here