我尝试将彩色矩形添加到树状图结果中,如下所示:
这是我的树状图代码:
from scipy.cluster.hierarchy import dendrogram
...
plt.figure(figsize=(250, 100))
labelsize=20
ticksize=15
plt.title(file_name.split(".")[0], fontsize=labelsize)
plt.xlabel('stock', fontsize=labelsize)
plt.ylabel('distance', fontsize=labelsize)
dendrogram(
Z,
leaf_rotation=90., # rotates the x axis labels
leaf_font_size=8., # font size for the x axis labels
labels = corr.columns
)
pylab.yticks(fontsize=ticksize)
pylab.xticks(rotation=-90, fontsize=ticksize)
但是,这只是添加彩色线,而不是上图中的矩形。我怎样才能创建这样的图像
谢谢
可以在生成的路径集合中循环并绘制边界框
或者,您可以将高度设置为
color_threshold=
参数,该参数默认为Z[:, 2].max() * 0.7
最后一个集合是未分类的行,因此下面的示例代码循环遍历所有早期集合
相关问题 更多 >
编程相关推荐