问题
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:
回答1:
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.
来源:https://stackoverflow.com/questions/5459341/dendrogram-generated-by-scipy-cluster-customisation