Plot unique DataFrame
s on the same axis
Plotting multiple series (not pandas
Series
) in a scatter can be accomplished by separating the DataFrame
s by a condition and then plotting them as separate scatters with unique colors on the same axis. This was shown in this answer. I will reproduce it here with your data.
Note: this was done in an iPython/Jupyter notebook
%matplotlib inline
import pandas as pd
from cStringIO import StringIO
# example data
text = '''
code proportion percent_highcost total_quantity
A81 0.7 76 1002
A81 0.0 73 1400
A81 0.1 77 1300
A81 0.0 74 1200
A81 -0.1 78 1350
'''
# read in example data
df = pd.read_csv(StringIO(text), sep='\s+')
print 'Original DataFrame:'
print df
print
# split the DataFrame into two DataFrames
condition = df['proportion'] > 0
df1 = df[condition].dropna()
df2 = df[~condition].dropna()
print 'DataFrame 1:'
print df1
print
print 'DataFrame 2:'
print df2
print
# Plot 2 DataFrames on one axis
ax = df1.plot(kind='scatter', x='total_quantity', y='percent_highcost', c='b', s=100, label='Non-Dispensing')
df2.plot(kind='scatter', x='total_quantity', y='percent_highcost', c='r', s=100, label='Dispensing', ax=ax)
Original DataFrame:
code proportion percent_highcost total_quantity
0 A81 0.7 76 1002
1 A81 0.0 73 1400
2 A81 0.1 77 1300
3 A81 0.0 74 1200
4 A81 -0.1 78 1350
DataFrame 1:
code proportion percent_highcost total_quantity
0 A81 0.7 76 1002
2 A81 0.1 77 1300
DataFrame 2:
code proportion percent_highcost total_quantity
1 A81 0.0 73 1400
3 A81 0.0 74 1200
4 A81 -0.1 78 1350
