ProficientInMath
ProficientInMath

Reputation: 69

Make scatter plot and color points with colors stored in data frame

I have a pandas dataframe with a column that has colors stored in it. Each row has data with an associated color. I would like to make a scatter plot of the data so that each point is colored according to the color stored in the same row. Below is an example of my dataframe:

 import pandas as pd
 df = pd.DataFrame({'dataX': [3,79,90], 'dataY': [7,9,13], 'color': ['Blue', 'Green', 'Red']})

    color  dataX  dataY
 0   Blue      3      7
 1  Green     79      9
 2    Red     90     13

so the point at index 0 will be blue, green at index 1 and so on.

Thanks in advance!

Upvotes: 0

Views: 1022

Answers (1)

user2285236
user2285236

Reputation:

Pass the color parameter c:

df.plot.scatter('dataX', 'dataY', c=df['color'])

enter image description here

Upvotes: 4

Related Questions