如何在 Seaborn 的聚类树状图中指定线宽

cli*_*val 2 python matplotlib seaborn

通常我会通过编辑 matplotlib.rcParams 来增加 matplotlib 的全局线宽。这似乎可以直接与SciPy 的树状图实现配合使用,但不适用于Seaborn 的 clustermap(它使用 SciPy 的树状图)。谁能建议一种工作方法?

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)
Run Code Online (Sandbox Code Playgroud)

小智 6

现在,以下合并的拉取请求已以更可靠的方式解决了这个问题:https://github.com/mwaskom/seaborn/pull/1935。我假设它将包含在 v0.9.0 之后的版本中。

您可以LineCollection使用tree_kws参数控制树状图的属性。

例如:

>>> import seaborn as sns
>>> iris = sns.load_dataset("iris")
>>> species = iris.pop("species")
>>> g = sns.clustermap(iris, tree_kws=dict(linewidths=1.5, colors=(0.2, 0.2, 0.4))
Run Code Online (Sandbox Code Playgroud)

将以另一种深紫色为树创建一个具有 1.5 pt 粗线的聚类图。