I am new to scipy but I managed to get the expected dendrogram. I am some more questions;
- In the dendrogram, distance between some points are
0
but its not visible due to image border. How can I remove the border and make the lower limit of y-axis to-1
, so that it is clearly visible. e.g. distance between these points are0
(13,17), (2,10), (4,8,19) - How can I prune/truncate on a particular distance. for e.g. prune at
0.4
- How to write these clusters(after pruning) to a file
My python code:
import scipy
import pylab
import scipy.cluster.hierarchy as sch
import numpy as np
D = np.genfromtxt('LtoR.txt', dtype=None)
def llf(id):
return str(id)
fig = pylab.figure(figsize=(10,10))
Y = sch.linkage(D, method='single')
Z1 = sch.dendrogram(Y,leaf_label_func=llf,leaf_rotation=90)
fig.show()
fig.savefig('dendrogram.png')
Dendrogram:
thank you.