How can I adjust the legend when visualizing clusters in two dimensions?
How can I change the legend as we can see now the legend has some cluster numbers missing. How can I adjust the legend so that it can show all the cluster numbers (such as Cluster 1, Cluster 2 etc, no it's only 0 3 6 9)? (codes I followed this link: Perform k-means clustering over multiple columns)
kmeans = KMeans(n_clusters=10)
y2 = kmeans.fit_predict(scaled_data)
reduced_scaled_data = PCA(n_components=2).fit_transform(scaled_data)
results = pd.DataFrame(reduced_scaled_data,columns=['pca1','pca2'])
sns.scatterplot(x="pca1", y="pca2", hue=y2, data=results)
#y2 is my cluster number
plt.title('K-means Clustering with 2 dimensions')
plt.show()
Edit: the legend seem not the same, the cluster 0 should be the lightest color.
Topic matplotlib pca python clustering
Category Data Science