import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.lines
raw_data = {'first_name': ['Jason', 'Molly', 'Tina', 'Jake', 'Amy'],
    'last_name': ['Miller', 'Jacobson', 'Ali', 'Milner', 'Cooze'], 'female':
    [0, 1, 1, 0, 1], 'age': [42, 52, 36, 24, 73], 'preTestScore': [4, 24, 
    31, 2, 3], 'postTestScore': [25, 94, 57, 62, 70], 'colors': ['r', 'g',
    'b', 'k', 'cyan']}
df = pd.DataFrame(raw_data, columns=['first_name', 'last_name', 'age',
    'female', 'preTestScore', 'postTestScore', 'colors'])
plt.scatter(df.preTestScore, df.postTestScore, s=df.age, c=df.colors)
handles = [matplotlib.lines.Line2D([], [], marker='o', color=c, linestyle=
    'none') for c in df.colors.values]
plt.legend(handles=handles, labels=list(df.last_name.values), loc=
    'upper left', prop={'size': 6}, bbox_to_anchor=(1, 1), ncol=1, numpoints=1)
plt.subplots_adjust(right=0.8)
plt.show()
Pandas Scatterplot Using Data Frame Fields to Derive Colors and Legend