How to specify linewidth in Seaborn's clustermap dendrograms

前端 未结 3 478
醉梦人生
醉梦人生 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:33

    There may be an easier way to do it, but this seems to work:

    import matplotlib
    import seaborn as sns; sns.set()
    
    flights = sns.load_dataset("flights")
    flights = flights.pivot("month", "year", "passengers")
    g = sns.clustermap(flights)
    for l in g.ax_row_dendrogram.lines:
            l.set_linewidth(10)
    for l in g.ax_col_dendrogram.lines:
            l.set_linewidth(10)
    

    Edit This no longer works in Seaborn v. 0.7.1 (and probably some earlier versions as well); g.ax_col_dendrogram.lines now returns an empty list. I couldn't find a way to increase line width and I ended up temporarily modifying the Seaborn module. In file matrix.py, function class _DendrogramPlotter, the linewidth is hard-coded as 0.5; I modified it to 1.5:

    line_kwargs = dict(linewidths=1.5, colors='k')

    This worked but obviously isn't a very sustainable approach.

提交回复
热议问题