title: Pandas Scatterplot Using Data Frame Fields to Derive Colors and Legend
body: <p>I want to create a scatterplot which shows two columns mapped against each other in pandas, a third for size, and then the color of the point based on the label (in the case below, last_name).</p>
  
  <p>I then want a legend that shows a dot for the color and then the last_name value</p>
  
  <p>Each last name should be associated with a different color and the legend shows, for example, a green dot and Miller, a red dot and Jacobson, etc.</p>
  
  <pre><code>%matplotlib inline
  import pandas as pd
  import matplotlib.pyplot as plt
  import numpy as np
  
  
  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]}
  df = pd.DataFrame(raw_data, columns = ['first_name', 'last_name', 'age', 'female', 'preTestScore', 'postTestScore'])
  
  plt.scatter(df.preTestScore, df.postTestScore, s=df.age, label=df.last_name)
  plt.legend(loc='upper left', prop={'size':6}, bbox_to_anchor=(1,1),ncol=1)
  </code></pre>
  
  <p>And that gives me something like this:</p>
  
  <p><a href="https://i.stack.imgur.com/qo3SW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qo3SW.png" alt="enter image description here"></a></p>
  
  <p>I can't figure out how to get the colors in at all (ideally, I'd love to use a palette) or how to get the legend to show the last name and the dot</p>
  
  <p>Any help would be much appreciated.. thanks!</p>
  
  <p>Note - I am taking the example from here <a href="http://chrisalbon.com/python/matplotlib_scatterplot_from_pandas.html" rel="nofollow noreferrer">Chris Albon</a>.</p>