是否可以在Seaborn的clustermap树形图中更改线宽?

问题描述 投票:1回答:1

基本上同样的问题被问到here。但答案不再适用。

提供的答案(由用户@iayork提供)涉及以下代码:

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)

但正如用户@iayork所指出的那样,这不再有效,g.ax_col_dendrogram.lines现在返回一个空列表。

python seaborn
1个回答
2
投票
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']])

# in newer versions, linecollections, instead of individual lines are used, 
# so, loop through those
for a in g.ax_row_dendrogram.collections:
    a.set_linewidth(10)

for a in g.ax_col_dendrogram.collections:
    a.set_linewidth(10)
© www.soinside.com 2019 - 2024. All rights reserved.