关于树状图的一些问题-python(Scipy) [英] Some questions on dendrogram - python (Scipy)

查看:140
本文介绍了关于树状图的一些问题-python(Scipy)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是scipy的新手,但我设法获得了预期的树状图。我还有其他问题;


  1. 在树状图中,某些点之间的距离为 0 ,但不是$ b由于图像边框,$ b可见。如何删除边框并使
    的y轴下限为 -1 ,以便清晰可见。
    例如这些点之间的距离是 0 (13,17),(2,10),(4,8,19)

  2. 如何我可以在特定距离上修剪/截断吗?例如 0.4

  3. 如何将这些簇(修剪后)写入文件

我的python代码:

  import scipy 
import pylab
import scipy.cluster.hierarchy as sch
import numpy as np

D = np.genfromtxt('LtoR.txt',dtype = None)
def llf(id ):
返回str(id)
图= 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')

树状图:


谢谢。

解决方案

1。 fig.gca()。set_ylim(-0.4,1.2)此处 gca()返回当前的 axes 对象,因此可以给它起一个名字

  ax = fig.gca() 
ax.set_ylim(-0.4,ax.get_ylim()[1])$ ​​b $ b


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:

thank you.

解决方案

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])

这篇关于关于树状图的一些问题-python(Scipy)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆