python - Scipy 树状图叶节点排序

标签 python scipy

我正在尝试更改 Scipy dendrogram 中叶节点的顺序情节功能。考虑以下代码段:

from scipy.cluster.hierarchy import linkage, dendrogram
import matplotlib.pyplot as plt
dists = [ 2., 10.,  3.]
lx = linkage(dists, 'complete')
dendrogram(lx)
plt.show()

生成的树状图是:

Dendrogram plot

我想在此图中将叶节点的顺序更改为 0, 1, 2。有没有一种简单的方法可以实现这一目标?

我尝试了 dendrogram 中参数 count_sortdistance_sort 的所有可能设置,但顺序保持不变。

最佳答案

以下评论出现在source code of the dendrogram scipy method :

# This feature was thought about but never implemented (still useful?):
#
#         ... = dendrogram(..., leaves_order=None)
#
#         Plots the leaves in the order specified by a vector of
#         original observation indices. If the vector contains duplicates
#         or results in a crossing, an exception will be thrown. Passing
#         None orders leaf nodes based on the order they appear in the
#         pre-order traversal.

所以这是一个相关的问题。您可以联系 Scipy 开发人员 (SciPy Project Mailing Lists) 表达您对此增强的兴趣,以便他们意识到它很有用并给予它更高的优先级。

关于python - Scipy 树状图叶节点排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51077293/

相关文章:

python - 修改多级词典

python - 导入 scipy.stats 时,获取 'ImportError: DLL load failed: The specified procedure could not be found'

python - 如何在solve_bvp中设置适当的边界条件?

编写列表列表的 Python csv 文件

python - 如何区分组引用和后面的数字?

python - Csr 矩阵 : How to replace missing value with np. nan 而不是 0?

python - 拟合分布、拟合优度、p 值。是否可以使用 Scipy (Python) 做到这一点?

python - 共轭梯度模块中的矩阵函数

SUD 的 Python 要求

python - 在数据框的列上应用 map 功能