scipy-cluster 定制生成的树状图
这是scipy-cluster生成的树状图不显示的后续内容。
from matplotlib.pyplot import show
from scipy.spatial.distance import pdist
from scipy.cluster.hierarchy import linkage, dendrogram
from numpy.random import rand
X = rand( 5, 3 )
X[0:5, :] *= 2
Y = pdist( X )
Z = linkage( Y )
dendrogram( Z )
show()
当dendrogram()
返回一个带有ivl、leaves、color_list、icoord
键的字典时,pyplot
正在拾取。在将标签和叶子长度传递给 pyplot 之前,如何修改它们?
做类似的事情:
d=dendrogram( Z )
d['leaves']=['label1','label2','label3','label4','label5']
似乎不影响它。
叶子长度应该是这样的:
This is a follow up to Dendrogram generated by scipy-cluster does not show.
from matplotlib.pyplot import show
from scipy.spatial.distance import pdist
from scipy.cluster.hierarchy import linkage, dendrogram
from numpy.random import rand
X = rand( 5, 3 )
X[0:5, :] *= 2
Y = pdist( X )
Z = linkage( Y )
dendrogram( Z )
show()
when dendrogram()
returns a dictionary with keys ivl, leaves, color_list, icoord
that pyplot
is picking up. How can I modify the labels and the leaf length before they are passed to pyplot
?
Doing something like:
d=dendrogram( Z )
d['leaves']=['label1','label2','label3','label4','label5']
does not seem to affect it.
The leaf length should be something like this:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据 树形图文档,您应该能够在调用时定义标签(通过labels或leaf_label_func参数)。因此无需事后尝试篡改标签。
According the dendrogram documentation, you should be able to define labels when you are calling it (either via labels or leaf_label_func args). So there is no need to try to tamper afterwards with labels.