In [1]:
import numpy as np
import pandas as pd

%pylab inline
import seaborn as sns
sns.set_style('darkgrid')


Populating the interactive namespace from numpy and matplotlib
/Users/davekensinger/anaconda/lib/python3.5/site-packages/matplotlib/__init__.py:872: UserWarning: axes.color_cycle is deprecated and replaced with axes.prop_cycle; please use the latter.
  warnings.warn(self.msg_depr % (key, alt_key))

In [2]:
names = [
       'mpg'
    ,  'cylinders'
    ,  'displacement'
    ,  'horsepower'
    ,  'weight'
    ,  'acceleration'
    ,  'model_year'
    ,  'origin'
    ,  'car_name'
]
df = pd.read_csv("http://archive.ics.uci.edu/ml/machine-learning-databases/auto-mpg/auto-mpg.data", sep='\s+', names=names)
df['maker'] = df.car_name.map(lambda x: x.split()[0])
df.origin = df.origin.map({1: 'America', 2: 'Europe', 3: 'Asia'})
df=df.applymap(lambda x: np.nan if x == '?' else x).dropna()
df['horsepower'] = df.horsepower.astype(float)
df.head()


Out[2]:
mpg cylinders displacement horsepower weight acceleration model_year origin car_name maker
0 18 8 307 130 3504 12.0 70 America chevrolet chevelle malibu chevrolet
1 15 8 350 165 3693 11.5 70 America buick skylark 320 buick
2 18 8 318 150 3436 11.0 70 America plymouth satellite plymouth
3 16 8 304 150 3433 12.0 70 America amc rebel sst amc
4 17 8 302 140 3449 10.5 70 America ford torino ford

In [5]:
g = sns.JointGrid(x="horsepower", y="mpg", data=df)
g.plot_joint(sns.regplot, order=2)
g.plot_marginals(sns.distplot)


Out[5]:
<seaborn.axisgrid.JointGrid at 0x10a8cc908>

In [6]:
sns.jointplot("mpg", "horsepower", data=df, kind='kde')


/Users/davekensinger/anaconda/lib/python3.5/site-packages/matplotlib/__init__.py:892: UserWarning: axes.color_cycle is deprecated and replaced with axes.prop_cycle; please use the latter.
  warnings.warn(self.msg_depr % (key, alt_key))
Out[6]:
<seaborn.axisgrid.JointGrid at 0x10e028400>

In [7]:
g = sns.PairGrid(df[["mpg", "horsepower", "weight", "origin"]], hue="origin")
g.map_upper(sns.regplot)
g.map_lower(sns.residplot)
g.map_diag(plt.hist)
for ax in g.axes.flat:
    plt.setp(ax.get_xticklabels(), rotation=45)
g.add_legend()
g.set(alpha=0.5)


/Users/davekensinger/anaconda/lib/python3.5/site-packages/matplotlib/__init__.py:892: UserWarning: axes.color_cycle is deprecated and replaced with axes.prop_cycle; please use the latter.
  warnings.warn(self.msg_depr % (key, alt_key))
Out[7]:
<seaborn.axisgrid.PairGrid at 0x10e23e9b0>

In [ ]: