Ahmed Abdullah
Ahmed Abdullah

Reputation: 345

Is it possible to change linewidth in Seaborn's clustermap dendrograms?

Essentially same question was asked here. But the answer no longer works.

The provided answer (by user @iayork) involved the following codes:

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)

But as pointed out by user @iayork this no longer works, the g.ax_col_dendrogram.lines now returns an empty list.

Upvotes: 1

Views: 363

Answers (1)

warped
warped

Reputation: 9481

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)

Upvotes: 2

Related Questions