title: Plotting the KMeans Cluster Centers for every iteration in Python
body: <p>I created a dataset with 6 clusters and visualize it with the code below, and find the cluster center points for every iteration, now i want to visualize demonstration of update of the cluster centroids in KMeans algorithm. This demonstration should include first four iterations by generating 2×2-axis figure.
  I found the points but i cant plot them, can you please check out my code and by looking that, help me write the algorithm to scatter plot?</p>
  <p>Here is my code so far:</p>
  <pre><code>import seaborn as sns
  import matplotlib.pyplot as plt
  %matplotlib inline
  from sklearn.datasets import make_blobs
  data = make_blobs(n_samples=200, n_features=8, 
                             centers=6, cluster_std=1.8,random_state=101)
  data[0].shape
  plt.scatter(data[0][:,0],data[0][:,1],c=data[1],cmap='brg')
  
  plt.show()
  from sklearn.cluster import KMeans
  
  print(&quot;First iteration points:&quot;)
  kmeans = KMeans(n_clusters=6,random_state=0,max_iter=1)
  kmeans.fit(data[0])
  centroids=kmeans.cluster_centers_
  print(kmeans.cluster_centers_)
  print(&quot;Second iteration points:&quot;)
  kmeans = KMeans(n_clusters=6,random_state=0,max_iter=2)
  kmeans.fit(data[0])
  print(kmeans.cluster_centers_)
  print(&quot;Third iteration points:&quot;)
  kmeans = KMeans(n_clusters=6,random_state=0,max_iter=3)
  kmeans.fit(data[0])
  print(kmeans.cluster_centers_)
  print(&quot;Forth iteration points:&quot;)
  kmeans = KMeans(n_clusters=6,random_state=0,max_iter=4)
  kmeans.fit(data[0])
  print(kmeans.cluster_centers_)
  </code></pre>