In [2]:
import numpy as np
from sklearn.cluster import KMeans
import matplotlib.pyplot as plt
In [3]:
X = np.array([[20, -40],   [300, -320], [300, -380], [360, -100],
              [360, -320], [80, -320],  [300, -100], [80, -40],
              [360, -380], [80, -100],  [20, -380],  [20, -100],
              [20, -320],  [360, -40],  [300, -40],  [80, -380]])
In [4]:
def get_points_by_cl_num(clusters, num):
    return X[np.where(clusters == num)]
In [5]:
n = 4

kmeans = KMeans(n_clusters=n)
kmeans.fit(X)
Out[5]:
KMeans(algorithm='auto', copy_x=True, init='k-means++', max_iter=300,
    n_clusters=4, n_init=10, n_jobs=1, precompute_distances='auto',
    random_state=None, tol=0.0001, verbose=0)
In [9]:
from random import choice
colors = ['red', 'green', 'blue', 'yellow']

for cl in range(n):
    print('Points in cluster {}:'.format(cl))
    print(get_points_by_cl_num(kmeans.labels_, cl), '\n')
    
    for x, y in get_points_by_cl_num(kmeans.labels_, cl):
        plt.scatter(x, y, c=colors[cl])

plt.show()
Points in cluster 0:
[[  80 -320]
 [  20 -380]
 [  20 -320]
 [  80 -380]] 

Points in cluster 1:
[[  20  -40]
 [  80  -40]
 [  80 -100]
 [  20 -100]] 

Points in cluster 2:
[[ 300 -320]
 [ 300 -380]
 [ 360 -320]
 [ 360 -380]] 

Points in cluster 3:
[[ 360 -100]
 [ 300 -100]
 [ 360  -40]
 [ 300  -40]]