Seaborn demo per Jake VanderPlas below


In [1]:
from __future__ import print_function, division

%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd

In [2]:
x = np.linspace(0, 10, 1000)
plt.plot(x, np.sin(x), x, np.cos(x));



In [3]:
import seaborn as sns
sns.set()
plt.plot(x, np.sin(x), x, np.cos(x));



In [4]:
data = np.random.multivariate_normal([0, 0], [[5, 2], [2, 2]], size=2000)
data = pd.DataFrame(data, columns=['x', 'y'])

for col in 'xy':
    plt.hist(data[col], normed=True, alpha=0.5)



In [5]:
for col in 'xy':
    sns.kdeplot(data[col], shade=True)



In [6]:
sns.distplot(data['x']);



In [7]:
sns.kdeplot(data);



In [8]:
with sns.axes_style('white'):
    sns.jointplot("x", "y", data, kind='kde');



In [9]:
with sns.axes_style('white'):
    sns.jointplot("x", "y", data, kind='hex')



In [10]:
iris = sns.load_dataset("iris")
iris.head()


Out[10]:
sepal_length sepal_width petal_length petal_width species
0 5.1 3.5 1.4 0.2 setosa
1 4.9 3.0 1.4 0.2 setosa
2 4.7 3.2 1.3 0.2 setosa
3 4.6 3.1 1.5 0.2 setosa
4 5.0 3.6 1.4 0.2 setosa

In [11]:
tips = sns.load_dataset('tips')
tips.head()


Out[11]:
total_bill tip sex smoker day time size
0 16.99 1.01 Female No Sun Dinner 2
1 10.34 1.66 Male No Sun Dinner 3
2 21.01 3.50 Male No Sun Dinner 3
3 23.68 3.31 Male No Sun Dinner 2
4 24.59 3.61 Female No Sun Dinner 4

In [12]:
tips['tip_pct'] = 100 * tips['tip'] / tips['total_bill']

grid = sns.FacetGrid(tips, row="sex", col="time", margin_titles=True)
grid.map(plt.hist, "tip_pct", bins=np.linspace(0, 40, 15));



In [13]:
with sns.axes_style(style='ticks'):
    g = sns.factorplot("day", "total_bill", "sex", data=tips, kind="box")
    g.set_axis_labels("Day", "Total Bill");



In [14]:
with sns.axes_style('white'):
    sns.jointplot("total_bill", "tip", data=tips, kind='hex')



In [15]:
sns.jointplot("total_bill", "tip", data=tips, kind='reg');



In [16]:
planets = sns.load_dataset('planets')
planets.head()


Out[16]:
method number orbital_period mass distance year
0 Radial Velocity 1 269.300 7.10 77.40 2006
1 Radial Velocity 1 874.774 2.21 56.95 2008
2 Radial Velocity 1 763.000 2.60 19.84 2011
3 Radial Velocity 1 326.030 19.40 110.62 2007
4 Radial Velocity 1 516.220 10.50 119.47 2009

In [17]:
with sns.axes_style('white'):
    g = sns.factorplot("year", data=planets, aspect=1.5)
    g.set_xticklabels(step=5)



In [18]:
with sns.axes_style('white'):
    g = sns.factorplot("year", data=planets, aspect=4.0,
                       hue='method', order=range(2001, 2015), kind="count")
    g.set_ylabels('Number of Planets Discovered')


Scikit-learn tutorial from pycon 2015 Jake VanderPlas here


In [ ]: