I am using plotly (to be able to get point information when I hoover over) to visualise my clustered scatter plot. I am having trouble with assigning different colours to the clusters I have produced by using KMeans. When plotting this in matplotlib.pyplot (as plt) I use the following code:
plt.scatter(restult[:,0], result[:,1], c=cluster_labels
cluster_labels being:
n_clusters = 3
km = KMeans(n_clusters).fit(result)
labels = km.labels_
And it works totally fine, but I need the hoover info.
This is where I am at so far with plotly:
trace = go.Scatter(
x = result[:,0],
y = result[:,1],
mode = 'markers',
text = index, # I want to see the index of each point
)
data = [trace]
# Plot and embed in ipython notebook!
py.iplot(data, filename='basic-scatter')
I appreciate the help!
marker=dict(color=kmeans.labels_)), just like in matplotlibfrom sklearn import datasets
from sklearn import cluster
import plotly
plotly.offline.init_notebook_mode()
iris = datasets.load_iris()
kmeans = cluster.KMeans(n_clusters=3,
random_state=42).fit(iris.data[:,0:2])
data = [plotly.graph_objs.Scatter(x=iris.data[:,0],
y=iris.data[:,1],
mode='markers',
marker=dict(color=kmeans.labels_)
)
]
plotly.offline.iplot(data)

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With