Title: Using Seaborn To Visualize A Pandas Dataframe
Slug: pandas_with_seaborn
Summary: Using Seaborn To Visualize A Pandas Dataframe
Date: 2016-05-01 12:00
Category: Python
Tags: Data Wrangling
Authors: Chris Albon

Preliminaries


In [2]:
import pandas as pd
%matplotlib inline
import random
import matplotlib.pyplot as plt
import seaborn as sns

In [3]:
df = pd.DataFrame()

df['x'] = random.sample(range(1, 100), 25)
df['y'] = random.sample(range(1, 100), 25)

In [4]:
df.head()


Out[4]:
x y
0 18 25
1 42 67
2 52 77
3 4 34
4 14 69

Scatterplot


In [5]:
sns.lmplot('x', 'y', data=df, fit_reg=False)


Out[5]:
<seaborn.axisgrid.FacetGrid at 0x114563b00>

Density Plot


In [6]:
sns.kdeplot(df.y)


Out[6]:
<matplotlib.axes._subplots.AxesSubplot at 0x113ea2ef0>

In [7]:
sns.kdeplot(df.y, df.x)


Out[7]:
<matplotlib.axes._subplots.AxesSubplot at 0x113d7fef0>

In [8]:
sns.distplot(df.x)


Out[8]:
<matplotlib.axes._subplots.AxesSubplot at 0x114294160>

Histogram


In [9]:
plt.hist(df.x, alpha=.3)
sns.rugplot(df.x);


Boxplot


In [10]:
sns.boxplot([df.y, df.x])


Out[10]:
<matplotlib.axes._subplots.AxesSubplot at 0x1142b8b38>

Violin Plot


In [11]:
sns.violinplot([df.y, df.x])


Out[11]:
<matplotlib.axes._subplots.AxesSubplot at 0x114444a58>

Heatmap


In [12]:
sns.heatmap([df.y, df.x], annot=True, fmt="d")


Out[12]:
<matplotlib.axes._subplots.AxesSubplot at 0x114530c88>

Clustermap


In [13]:
sns.clustermap(df)


Out[13]:
<seaborn.matrix.ClusterGrid at 0x116f313c8>