是否可以更改Seaborn群集图树状图中的线宽?

时间:2019-04-28 08:39:14

标签: python seaborn

本质上是相同的问题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现在返回一个空列表。

1 个答案:

答案 0 :(得分: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)