additional row colors in seaborn cluster map

前端 未结 3 809
遥遥无期
遥遥无期 2021-02-06 09:17

I am currently generating clustermaps in seaborn and labeling the row colors as below.

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


        
3条回答
  •  离开以前
    2021-02-06 09:37

    The solution is below. The seaborn API does actually allow this to be done.

    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)
    
    g=sns.clustermap(matrix, col_cluster=False, linewidths=0.1, cmap='coolwarm', row_colors=[row_colors, row_colors2])
    plt.show()
    

    This produces a Clustermap with two additional columns: Clustermap with two additional columns

提交回复
热议问题