Alex Kinman Alex Kinman - 1 year ago 117
Python Question

Color coding or labelling the scatter plot of a pandas dataframe?

I have a data frame that I am plotting in pandas:

import pandas as pd
df = pd.read_csv('Test.csv')

the data frame has 3 columns

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

I want to format the scatter plot such that each point is green if df['result']='Good' and red if df['result']='Bad'.

Can do that using pd.plot or is there a way of doing it using pyplot?

Answer Source
df.plot.scatter('x', 'y','green', Bad='red')))

enter image description here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download