Title: Making A Matplotlib Scatterplot From A Pandas Dataframe
Slug: matplotlib_scatterplot_from_pandas
Summary: Making A Matplotlib Scatterplot From A Pandas Dataframe
Date: 2016-05-01 12:00
Category: Python
Tags: Data Visualization
Authors: Chris Albon
Based on: StackOverflow.
In [1]:
%matplotlib inline
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
In [2]:
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'])
df
Out[2]:
In [3]:
plt.scatter(df.preTestScore, df.postTestScore
, s=df.age)
Out[3]:
In [5]:
plt.scatter(df.preTestScore, df.postTestScore, s=300, c=df.female)
Out[5]: