小编Sta*_*ish的帖子

如何在python中使用scipy为树形图中的部分链接着色?

我可以在Python树形图中为标签着色,但我不知道如何对属于其标签的链接的部分进行着色..我想做这样的事情:

http://winedarksea.org/wp-content/uploads/2009/11/PCCovariance1and2WardDendrogram1-815x1024.jpg

在Python中有可能吗?

这里我只标注颜色:

import numpy as np
import matplotlib.pyplot as plt
import scipy.cluster.hierarchy as sc

dists = np.array([[0,2,1,4],[2,0,3,5],[1,3,0,6],[4,5,6,0]])
l = ['a','b','c','b']
Z = sc.linkage(dists, method='complete')
d = sc.dendrogram(Z, labels=l)
label_colors = {'a': 'r', 'b': 'g', 'c': 'm'}
ax = plt.gca()
xlbls = ax.get_xmajorticklabels()
for i in range(len(xlbls)):
    xlbls[i].set_color(label_colors[xlbls[i].get_text()])
plt.show()
Run Code Online (Sandbox Code Playgroud)

python colors dendrogram scipy

7
推荐指数
1
解决办法
2774
查看次数

标签 统计

colors ×1

dendrogram ×1

python ×1

scipy ×1