Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit dc45d03

Browse files
authored
DOC Rework plot_kmeans_stability_low_dim_dense.py to make it more colorblind friendly (#24323)
1 parent 2f5a236 commit dc45d03

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

examples/cluster/plot_kmeans_stability_low_dim_dense.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,13 @@ def make_data(random_state, n_samples_per_center, grid_size, scale):
7474
legends = []
7575

7676
cases = [
77-
(KMeans, "k-means++", {}),
78-
(KMeans, "random", {}),
79-
(MiniBatchKMeans, "k-means++", {"max_no_improvement": 3}),
80-
(MiniBatchKMeans, "random", {"max_no_improvement": 3, "init_size": 500}),
77+
(KMeans, "k-means++", {}, "^-"),
78+
(KMeans, "random", {}, "o-"),
79+
(MiniBatchKMeans, "k-means++", {"max_no_improvement": 3}, "x-"),
80+
(MiniBatchKMeans, "random", {"max_no_improvement": 3, "init_size": 500}, "d-"),
8181
]
8282

83-
for factory, init, params in cases:
83+
for factory, init, params, format in cases:
8484
print("Evaluation of %s with %s init" % (factory.__name__, init))
8585
inertia = np.empty((len(n_init_range), n_runs))
8686

@@ -95,7 +95,9 @@ def make_data(random_state, n_samples_per_center, grid_size, scale):
9595
**params,
9696
).fit(X)
9797
inertia[i, run_id] = km.inertia_
98-
p = plt.errorbar(n_init_range, inertia.mean(axis=1), inertia.std(axis=1))
98+
p = plt.errorbar(
99+
n_init_range, inertia.mean(axis=1), inertia.std(axis=1), fmt=format
100+
)
99101
plots.append(p[0])
100102
legends.append("%s with %s init" % (factory.__name__, init))
101103

@@ -115,7 +117,7 @@ def make_data(random_state, n_samples_per_center, grid_size, scale):
115117
for k in range(n_clusters):
116118
my_members = km.labels_ == k
117119
color = cm.nipy_spectral(float(k) / n_clusters, 1)
118-
plt.plot(X[my_members, 0], X[my_members, 1], "o", marker=".", c=color)
120+
plt.plot(X[my_members, 0], X[my_members, 1], ".", c=color)
119121
cluster_center = km.cluster_centers_[k]
120122
plt.plot(
121123
cluster_center[0],

0 commit comments

Comments
 (0)