具有层次聚类的颜色的图聚类

问题描述 投票:0回答:1
#Plot the figure

plt.figure(1);
plt.clf();
plt.scatter(data[0,:],data[1,:]);
plt.xlabel('x');
plt.ylabel('y');
plt.title("Plot of all points from CURE dataset")

enter image description here

#Make dendrogram 

Y=pdist(data,'euclid');
distances=squareform(Y);
c=linkage(data,method='single');
dendrogram(Z);
idx = fcluster(Z,5,'maxclust');

enter image description here

我想根据它们所属的群集为点着色,该怎么做?

python matplotlib hierarchical-clustering
1个回答
0
投票

好吧,我想出了答案。只需取idx值(代表簇),然后使用以下命令进行绘制即可:

plt.scatter(data[:,0], data[:,1], c=idx, cmap='rainbow')

enter image description here

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