Hey everyone, when plotting the cluster assignment/labels output from scikit’s k-means with matplotlib one can do this:
plt.scatter(sqrt(X[:,0]), sqrt(X[:,1]), s = 100, c = k_means.labels_ , alpha=0.4)
plt.autoscale(tight=True)
Matplotlib will chose colors from the k_means.labels array that might look like [0,1,2,0,1,0,0,0,2]
Doing something similar in Bokeh, doesn’t work:
from bokeh.plotting import *
output_notebook()
scatter(X[:,0],X[:,1], c = k_means.labels_ , alpha=0.4,
fill_alpha=0.6, name=“color_scatter_example”, title = “k-means clusters”)
Is there something better than manually mapping the color with an array that explicitly defines colors like:
color_list =
for i in k_means.labels_:
if i == 0:
color_list.append(’#d18096’)
elif i ==1:
color_list.append(’#483496’)
else:
color_list.append(’#00FFD0’)