How to specify line width in Seaborn cluster dendrograms

Normally, I would increase the width of the matplotlib lines by editing matplotlib.rcParams. This seems to work well directly with SciPy dendrogram , but not with the Marine Cluster Map (which uses SciPy dendrograms). Can anyone suggest a working method?

import matplotlib matplotlib.rcParams['lines.linewidth'] = 10 import seaborn as sns; sns.set() flights = sns.load_dataset("flights") flights = flights.pivot("month", "year", "passengers") g = sns.clustermap(flights) 
+2
source share
2 answers

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

 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) 

Change This no longer works in Seaborn v. 0.7.1 (and probably some earlier versions); g.ax_col_dendrogram.lines now returns an empty list. I could not find a way to increase the line width, and in the end I temporarily changed the Seaborn module. In the matrix.py file, class _DendrogramPlotter function, the line width is hardcoded as 0.5; I changed it to 1.5:

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

This worked, but obviously not a very sustainable approach.

+2
source

for newer versions of seaborn (tested with 0.7.1, 0.9.0), the lines are in the LineCollection, and not by themselves. Thus, 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) 
0
source

Source: https://habr.com/ru/post/1264631/


All Articles