[英]How to plot DENDROGRAM in GUI
I am using a GUI from QtDesigner to plot Dendrogram.我正在使用从 QtDesigner 到 plot Dendrogram 的 GUI。 My code is below, but I can not plot the Dendrogram, how can I fix it?我的代码在下面,但我不能 plot 树状图,我该如何解决?
Error: 'AxesSubplot' object has no attribute 'dendrogram'
def dendro(self):
Z = linkage(X, method='ward', metric='euclidean', optimal_ordering=True)
c, coph_dists = cophenet(Z, pdist(X))
self.ui.linecoef.setText("%.3f" %c)
fig3 = Figure()
self.canvas3 = FigureCanvas(fig3)
self.ui.verticalLayout3.addWidget(self.canvas3)
fig3.subplots_adjust(top=0.93,bottom=0.125,left=0.1,right=0.97)
ax3f1 = fig3.add_subplot(121)
ax3f1.dendrogram(Z,leaf_rotation=90., leaf_font_size=8.,)
ax3f1.set_title('Hierarchical Clustering Dendrogram (full)')
ax3f1.set_xlabel('sample clusters')
ax3f1.set_ylabel('distance')
ax3f2 = fig3.add_subplot(122)
ax3f2.dendrogram(Z,truncate_mode='lastp', p=12, show_leaf_counts=True, show_contracted=True)
ax3f2.set_title('Hierarchical Clustering Dendrogram (truncated)')
ax3f2.set_xlabel('sample clusters size')
ax3f2.set_ylabel('distance')
self.canvas3.draw()
You have to import the dendrogram from scipy:您必须从 scipy 导入树状图:
from scipy.cluster import hierarchy
And then pass it the axes through the ax argument:然后通过 ax 参数将坐标轴传递给它:
ax3f1 = fig3.add_subplot(121)
hierarchy.dendrogram.dendrogram(
Z, ax=ax3f2, leaf_rotation=90.0, leaf_font_size=8.0
)
ax3f1.set_title("Hierarchical Clustering Dendrogram (full)")
ax3f1.set_xlabel("sample clusters")
ax3f1.set_ylabel("distance")
ax3f2 = fig3.add_subplot(122)
hierarchy.dendrogram(
Z,
ax=ax3f2,
truncate_mode="lastp",
p=12,
show_leaf_counts=True,
show_contracted=True,
)
ax3f2.set_title("Hierarchical Clustering Dendrogram (truncated)")
ax3f2.set_xlabel("sample clusters size")
ax3f2.set_ylabel("distance")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.