Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Some questions on dendrogram - python (Scipy)

I am new to scipy but I managed to get the expected dendrogram. I am some more questions;

  1. 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 are 0 (13,17), (2,10), (4,8,19)
  2. How can I prune/truncate on a particular distance. for e.g. prune at 0.4
  3. 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: enter image description here

thank you.

like image 749
Maggie Avatar asked Nov 04 '22 03:11

Maggie


1 Answers

1.fig.gca().set_ylim(-0.4,1.2) Here gca() returns the current axes object, so you can give it a name

ax=fig.gca()
ax.set_ylim(-0.4,ax.get_ylim()[1])
like image 75
ev-br Avatar answered Nov 09 '22 16:11

ev-br