Python 熊猫数据帧散点图的颜色编码或标签?

Python 熊猫数据帧散点图的颜色编码或标签?,python,pandas,matplotlib,plot,dataframe,Python,Pandas,Matplotlib,Plot,Dataframe,我有一个我正在绘制的数据框: import pandas as pd df = pd.read_csv('Test.csv') df.plot.scatter(x='x',y='y') 数据框有3列 x y result 0 2 5 Good 1 3 2 Bad 2 4 1 Bad 3 1 1 Good 4 2 23 Bad 5 1 34 Good 我想格式化散点图,使每个点在df['result']=“Go

我有一个我正在绘制的数据框:

import pandas as pd
df = pd.read_csv('Test.csv')
df.plot.scatter(x='x',y='y')
数据框有3列

    x   y result
 0  2   5  Good 
 1  3   2    Bad
 2  4   1    Bad
 3  1   1  Good 
 4  2  23    Bad
 5  1  34  Good
我想格式化散点图,使每个点在df['result']=“Good”时为绿色,在df['result']=“Bad”时为红色


可以使用pd.plot来实现这一点,或者有没有一种方法可以使用pyplot来实现这一点

一种方法是在同一轴上绘制两次。首先我们只画“好”点,然后我们只画“坏”点。诀窍是将
ax
关键字用于
scatter
方法,例如:

ax = df[df.result == 'Good'].plot.scatter('x', 'y', color='green')
df[df.result == 'Bad'].plot.scatter('x', 'y', ax=ax, color='red')

可能重复
df.plot.scatter('x', 'y', c=df.result.map(dict(Good='green', Bad='red')))