作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
documentation表示,“显示的树状图树的级别不超过 p
。“级别”包括上次合并中具有 p
合并的所有节点。” (p
是另一个参数)我搞不懂“p
merges from the last merge”是什么意思。谁能解释一下?
(我使用 truncate_mode='level'
和 truncate_mode='lastp'
创建了相同数据的树状图;我没有发现比较有启发性。)
最佳答案
以下代码演示了 truncate_mode='level'
和 truncate_mode='lastp'
:
from scipy.cluster import hierarchy
import matplotlib.pyplot as plt
import numpy as np
np.random.seed(1729)
ytdist = np.random.randint(1, 1000, 36)
Z = hierarchy.linkage(ytdist, 'single')
fig, ax_rows = plt.subplots(ncols=6, nrows=2, sharey=True, figsize=(16, 5))
for ax_row, truncate_mode in zip(ax_rows, ['level', 'lastp']):
hierarchy.dendrogram(Z, ax=ax_row[0])
ax_row[0].set_title('default, no truncation')
for ind, ax in enumerate(ax_row[1:]):
if truncate_mode == 'level':
p = len(ax_row) - ind - 1
else:
p = len(ax_row) - ind
hierarchy.dendrogram(Z, truncate_mode=truncate_mode, p=p, ax=ax)
ax.set_title(f"truncate_mode='{truncate_mode}', p={p}")
plt.tight_layout()
plt.show()
关于python - scipy.cluster.hierarchy.dendrogram() : exactly what does truncate_mode ='level' do?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66180002/
documentation表示,“显示的树状图树的级别不超过 p。“级别”包括上次合并中具有 p 合并的所有节点。” (p 是另一个参数)我搞不懂“p merges from the last mer
我是一名优秀的程序员,十分优秀!