Skip to main content
 首页 » 编程设计

python之如何在 Seaborn 的 clustermap 树状图中指定线宽

2024年10月24日34duanxz

通常我会通过编辑 matplotlib.rcParams 来增加 matplotlib 的全局线宽。这似乎直接适用于 SciPy's dendrogram实现但不使用 Seaborn's 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) 

请您参考如下方法:

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

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

例如:

>>> 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)) 

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