Skip to content

Commit bdfd838

Browse files
gusennanamueller
authored andcommitted
Use tuples for color specification (scikit-learn#9149)
In the Matplotlib 'Specifying Colors' section, neither list nor array is a valid color specification type. When this example is run using Python 3.5, and matplotlib 2.0.2 (latest), it errors with the message: "ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()" This change preserves the semantics of the example while allowing it to successfully run by converting to tuples for the matplotlib color specification.
1 parent 508e2f7 commit bdfd838

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

examples/cluster/plot_dbscan.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,16 @@
5757
for k, col in zip(unique_labels, colors):
5858
if k == -1:
5959
# Black used for noise.
60-
col = 'k'
60+
col = [0, 0, 0, 1]
6161

6262
class_member_mask = (labels == k)
6363

6464
xy = X[class_member_mask & core_samples_mask]
65-
plt.plot(xy[:, 0], xy[:, 1], 'o', markerfacecolor=col,
65+
plt.plot(xy[:, 0], xy[:, 1], 'o', markerfacecolor=tuple(col),
6666
markeredgecolor='k', markersize=14)
6767

6868
xy = X[class_member_mask & ~core_samples_mask]
69-
plt.plot(xy[:, 0], xy[:, 1], 'o', markerfacecolor=col,
69+
plt.plot(xy[:, 0], xy[:, 1], 'o', markerfacecolor=tuple(col),
7070
markeredgecolor='k', markersize=6)
7171

7272
plt.title('Estimated number of clusters: %d' % n_clusters_)

0 commit comments

Comments
 (0)