How to specify linewidth in Seaborn's clustermap dendrograms

前端 未结 3 475
醉梦人生
醉梦人生 2021-01-21 19:53

Normally I would increase matplotlib\'s global linewidths by editing the matplotlib.rcParams. This seems to work well directly with SciPy\'s dendrogram implementation but not wi

3条回答
  •  清酒与你
    2021-01-21 20:15

    for newer versions of seaborn (tested with 0.7.1, 0.9.0), the lines are in a LineCollection, rather than by themselves. So their width can be changed as follows:

    import seaborn as sns
    import matplotlib.pyplot as plt
    
    # load data and make clustermap
    df = sns.load_dataset('iris')
    g = sns.clustermap(df[['sepal_length', 'sepal_width']])
    
    for a in g.ax_row_dendrogram.collections:
        a.set_linewidth(10)
    
    for a in g.ax_col_dendrogram.collections:
        a.set_linewidth(10)
    

提交回复
热议问题