6

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.

enter image description here

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.

2 Answers 2

3

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')
Sign up to request clarification or add additional context in comments.

Comments

2

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)

1 Comment

It didn't worked. i am getting this error ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.