DOC Rework `plot_affinity_propagation.py` to make it colorblind friendly
@@ -8,6 +8,7 @@ Brendan J. Frey and Delbert Dueck, "Clustering by Passing Messages
Between Data Points", Science Feb. 2007
"""
+import numpy as np
from sklearn.cluster import AffinityPropagation
from sklearn import metrics
@@ -48,27 +49,26 @@ print(
# Plot result
# -----------
import matplotlib.pyplot as plt
-from itertools import cycle
plt.close("all")
plt.figure(1)
plt.clf()
-colors = cycle("bgrcmykbgrcmykbgrcmykbgrcmyk")
+colors = plt.cycler("color", plt.cm.viridis(np.linspace(0, 1, 4)))
+
for k, col in zip(range(n_clusters_), colors):
class_members = labels == k
cluster_center = X[cluster_centers_indices[k]]
- plt.plot(X[class_members, 0], X[class_members, 1], col + ".")
- plt.plot(
- cluster_center[0],
- cluster_center[1],
- "o",
- markerfacecolor=col,
- markeredgecolor="k",
- markersize=14,
+ plt.scatter(
+ X[class_members, 0], X[class_members, 1], color=col["color"], marker="."
+ )
+ plt.scatter(
+ cluster_center[0], cluster_center[1], s=14, color=col["color"], marker="o"
)
for x in X[class_members]:
- plt.plot([cluster_center[0], x[0]], [cluster_center[1], x[1]], col)
+ plt.plot(
+ [cluster_center[0], x[0]], [cluster_center[1], x[1]], color=col["color"]
+ )
plt.title("Estimated number of clusters: %d" % n_clusters_)
plt.show()
