Reputation: 2810
I am trying to plot k-means cluster using plotly, but i am having trouble in assigning colors based on there groups? I have following data frame.
group: cluster number
I am using this for scatter plot in plotly.
clustered.iplot(kind='scatter',x='value1',y='value2', colors = {'[clustered['group']==1]':'green', '[clustered['group']==0]':'yellow'},mode='markers',size=10)
Its wrong because it will only get True and false for color dict object. How i can can associate these group values so that color of points appear differently in the plot.
Upvotes: 6
Views: 9880
Reputation: 27430
Instead of using cufflinks
you can use the new Plotly Express library (https://plotly.express) to do this with:
px.scatter(clustered, x='value1', y='value2', color='group')
Upvotes: 3
Reputation: 394
If you only have two clusters, you can map the values:
clustered.iplot(kind='scatter', x='value1', y='value2', colors=clustered['group'].map({0:'yellow', 1:'green'}), mode='markers',size=10)
Upvotes: 2