本文介绍了如何在 Seaborn 的 clustermap 树状图中指定线宽的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
通常我会通过编辑 matplotlib.rcParams 来增加 matplotlib 的全局线宽.这似乎直接适用于 SciPy 的树状图 实现,但不包含 Seaborn 的集群图(使用 SciPy 的树状图).任何人都可以提出一种工作方法吗?
Normally I would increase matplotlib's global linewidths by editing the matplotlib.rcParams. This seems to work well directly with SciPy's dendrogram implementation but not with Seaborn's clustermap (which uses SciPy's 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)
推荐答案
对于较新版本的 seaborn(使用 0.7.1、0.9.0 测试),这些行位于 LineCollection 中,而不是它们本身.所以它们的宽度可以改变如下:
for newer versions of seaborn (tested with 0.7.1, 0.9.0), the lines are in a LineCollection, rather than by themselves. So 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)
这篇关于如何在 Seaborn 的 clustermap 树状图中指定线宽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!