简体   繁体   English

使用存储在数据框中的颜色制作散点图和色点

[英]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. 因此索引0处的点将是蓝色,索引1处的绿色,依此类推。

Thanks in advance! 提前致谢!

Pass the color parameter c : 传递颜色参数c

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

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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