更改散点图y轴

时间:2020-02-10 00:08:54

标签: python matplotlib k-means scatter-plot subplot

在python中,我将群集绘制成散点图。

但是,无论我将ylim(,)更改为什么值,y轴仍显示为0到6。有人知道为什么吗?以及如何放大以查看[0,2] * [0,2]周围的点?

谢谢!

    from sklearn.cluster import KMeans
    kmeans = KMeans(n_clusters=7, random_state=0).fit(X) 

    plt.figure(figsize=(5,5))

    trueK = 7 # Desired number of clusters
    colors = 'bgrykcm' # the letters are defining colors for each K. For instance, b is blue and g is gray. 

    plt.subplot(1,2,2)    
    for J in range(trueK):
        X_J = X[kmeans.labels_==J]
        plt.title("Clusters")
        plt.scatter(X_J[:, 0], X_J[:, 1], c=colors[J], s=10)
        plt.xlim(0,2)
        plt.ylim(0,2)
        plt.axis('equal')
    plt.show()  
  • y轴仍显示为0到6。 edit note the scale in graphic do not show in image link

0 个答案:

没有答案