我正在尝试更改 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()
生成的树状图是:
我想在此图中将叶节点的顺序更改为 0, 1, 2
。有没有一种简单的方法可以实现这一目标?
我尝试了 dendrogram
中参数 count_sort
和 distance_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/