树形图标签重叠

问题描述 投票:1回答:1

我有一个带标签的关系数据的2D数组(第一行和第一列)。

当我创建树形图时,我的标签重叠了。如何使标签均匀分开?

enter image description here

file= open(fileName)
line = file.readline()
file.close()
populations=line.split('\t')
del populations[0]


data = np.loadtxt(fileName, delimiter="\t",skiprows=1,usecols=range(1,len(populations)+1 ))

fig, ax = plt.subplots()

Y1 = sch.linkage(data, method='ward',optimal_ordering=True)

Z1 = sch.dendrogram(Y1, orientation='top')

ind1= Z1['leaves']
arr = np.array(populations)
populations = arr[ind1]
ax.set_xticks([])
ax.set_xticks(np.arange(len(populations)))
ax.set_xticklabels(populations )
plt.xticks(rotation=90)

plt.show()
python plot label dendrogram
1个回答
0
投票

我认为在树形图的构造中简单地指定标签可能更容易,因为它们在构造时是已知的,如下所示

import scipy.cluster.hierarchy as sch
import numpy as np           # Only needed for random sample data

np.random.seed(1)            # Seeded for reproducing

populations = np.arange(10)  # Create some random sample data
data = abs(np.random.randn(10))

fig, ax = plt.subplots()

Y1 = sch.linkage(data, method='ward',optimal_ordering=True)
Z1 = sch.dendrogram(Y1, orientation='top', labels=populations)

plt.show()

会给你的

© www.soinside.com 2019 - 2024. All rights reserved.