简体   繁体   中英

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!

Pass the color parameter c :

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

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM