【问题标题】:Plot Clusters with Color from Hierarchical Clustering用层次聚类的颜色绘制聚类
【发布时间】:2020-04-08 03:42:18
【问题描述】:
#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")

#Make dendrogram 

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

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

【问题讨论】:

    标签: python matplotlib hierarchical-clustering


    【解决方案1】:

    好的,我想出了答案。只需取代表集群的idx 值,然后使用以下命令进行绘图:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-06-28
      • 2016-08-07
      • 2013-05-08
      • 2018-10-04
      • 2020-06-28
      • 2016-06-06
      • 1970-01-01
      • 2016-09-06
      相关资源
      最近更新 更多