additional row colors in seaborn cluster map

前端 未结 3 747
遥遥无期
遥遥无期 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:46

    I tried to concat the row_colors dataframe by pandas and it worked! Please try this code:

    import seaborn as sns; sns.set(color_codes=True)
    import matplotlib.pyplot as plt
    import pandas as pd
    
    iris = sns.load_dataset("iris")
    print(iris)
    species = iris.pop("species")
    
    
    lut1 = dict(zip(species.unique(), ['#ED2323','#60FD00','#808080']))
    row_colors1 = species.map(lut1)
    
    lut2 = dict(zip(species.unique(), "rbg"))
    row_colors2 = species.map(lut2)
    
    row_colors = pd.concat([row_colors1,row_colors2],axis=1)
    print(row_colors)
    
    g = sns.clustermap(iris, row_colors=row_colors, col_cluster=False,cmap="mako", yticklabels=False, xticklabels=False)
    
    plt.show()
    

提交回复
热议问题