'''Simple Cluster plot using MeanShift and Bandwith Estimation'''

import numpy as np
import matplotlib.pyplot as plt
from sklearn.cluster import MeanShift, estimate_bandwidth
from itertools import cycle

def cluster_plot(X,n_clus):
    bandwidth = estimate_bandwidth(X, quantile = 0.1)
    ms = MeanShift(bandwidth = bandwidth, bin_seeding = True)
    ms.fit(X)
    labels = ms.labels_
    cluster_centers = ms.cluster_centers_
    labels_unique = np.unique(labels)
    n_clusters_ = n_clus
    print("Number of estimated clusters : %d " % n_clusters_ )
    plt.figure()
    plt.clf()
    colors = cycle('bgrcmykbgrcmy"kbgrcmykbgrcmyk')
    for k,col in zip(range(n_clusters_),colors):
        my_members = labels == k
        cluster_center = cluster_centers[k]
        plt.plot(X[my_members,0], X[my_members,1], col + '.')
        plt.plot(cluster_center[0], cluster_center[1], 'o', markerfacecolor = col, markeredgecolor = 'k', markersize = 14)
    plt.title('Estimated number of clusters: %d ' % n_clusters_)
    plt.show()