In [5]:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from mpl_toolkits import mplot3d
%matplotlib inline
In [9]:
fig = plt.figure()
ax = plt.axes(projection='3d')
data_z = 15 * np.random.random(200)
data_x = np.sin(data_z) + 0.1 * np.random.randn(200)
data_y = np.cos(data_z) + 0.1 * np.random.randn(200)
ax.scatter3D(data_x, data_y, data_z, c=data_z, cmap="Reds")
Out[9]:
In [10]:
rng = np.random.RandomState(0)
x = np.linspace(0, 10, 500)
y = np.cumsum(rng.randn(500, 6), 0)
plt.plot(x, y)
plt.legend('123456', ncol=2, loc='upper left')
Out[10]:
In [13]:
data = np.random.multivariate_normal([0, 0], [[5, 2], [2, 2]], size=2000)
df = pd.DataFrame(data, columns=['x', 'y'])
sns.distplot(df['x'])
Out[13]:
In [14]:
sns.jointplot('x', 'y', df)
Out[14]:
In [15]:
iris = sns.load_dataset('iris')
sns.pairplot(iris, hue='species', size=2.5)
Out[15]:
In [22]:
tips = sns.load_dataset('tips')
print(tips.head())
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, 50, 20));
In [23]:
sns.jointplot('total_bill', 'tip', data=tips, kind='reg')
Out[23]:
In [45]:
df = pd.read_csv('marathon-data.csv')
df['split_secs'] = df['split'].apply(pd.to_timedelta).astype(int) / 1E9
df['final_secs'] = df['final'].apply(pd.to_timedelta).astype(int) / 1E9
df.head()
Out[45]:
In [47]:
g = sns.jointplot('split_secs', 'final_secs', df)
g.ax_joint.plot(np.linspace(4000, 16000), np.linspace(8000, 32000)) # reference if the speed is steady
Out[47]:
In [50]:
df['split_frac'] = 1 - 2 * df['split_secs'] / df['final_secs'] # split_frac indicates if a person reduces the speed (>0) or increases the speed (<0)
df.head()
Out[50]:
In [51]:
sns.kdeplot(df.split_frac[df.gender=='M'], label='male', shade=True)
sns.kdeplot(df.split_frac[df.gender=='W'], label='female', shade=True)
plt.xlabel('split_frac')
Out[51]:
In [53]:
sns.violinplot('gender', 'split_frac', data=df, palette=['lightblue', 'pink'])
Out[53]:
In [3]:
anscombe = sns.load_dataset('anscombe')
In [8]:
sns.lmplot(x='x', y='y', data=anscombe.query("dataset=='I'"), ci=None, scatter_kws={'s': 50})
Out[8]:
In [11]:
sns.lmplot(x='x', y='y', data=anscombe.query("dataset=='II'"), ci=None, scatter_kws={'s': 50}, order=2)
Out[11]:
In [13]:
tips = sns.load_dataset('tips')
tips.head()
Out[13]:
In [14]:
tips['tip_pct'] = tips['tip'] / tips['total_bill'] * 100
tips.head()
Out[14]:
In [16]:
sns.lmplot(x='total_bill', y='tip_pct', data=tips)
Out[16]:
In [17]:
sns.lmplot(x='total_bill', y='tip_pct', hue='sex', data=tips)
Out[17]:
In [18]:
sns.lmplot(x='total_bill', y='tip_pct', hue='sex', col='time', data=tips)
Out[18]:
In [21]:
sns.stripplot(x='day', y='tip_pct', data=tips, jitter=True)
Out[21]:
In [23]:
sns.swarmplot(x='day', y='tip_pct', data=tips)
Out[23]:
In [ ]: