Seaborn

The Data

We will be working with the famous titanic data set for these exercise with a focus on the visualization of the data

In [1]:
import seaborn as sns
import matplotlib.pyplot as plt
%matplotlib inline
In [2]:
sns.set_style('whitegrid')
In [3]:
titanic = sns.load_dataset('titanic')
In [4]:
titanic.head()
Out[4]:
survived pclass sex age sibsp parch fare embarked class who adult_male deck embark_town alive alone
0 0 3 male 22.0 1 0 7.2500 S Third man True NaN Southampton no False
1 1 1 female 38.0 1 0 71.2833 C First woman False C Cherbourg yes False
2 1 3 female 26.0 0 0 7.9250 S Third woman False NaN Southampton yes True
3 1 1 female 35.0 1 0 53.1000 S First woman False C Southampton yes False
4 0 3 male 35.0 0 0 8.0500 S Third man True NaN Southampton no True

Joint Plot

In [5]:
sns.jointplot(x='fare',y='age',data=titanic)
Out[5]:
<seaborn.axisgrid.JointGrid at 0x11158cdd8>

Distribution Plot

In [6]:
sns.distplot(titanic["fare"],kde=False, bins=30)
Out[6]:
<matplotlib.axes._subplots.AxesSubplot at 0x10a8ab470>

Box Plot

In [7]:
sns.boxplot(x='class',y='age',data=titanic)
Out[7]:
<matplotlib.axes._subplots.AxesSubplot at 0x114597c50>

Swarm plot

In [8]:
sns.swarmplot(x='class',y='age',data=titanic)
Out[8]:
<matplotlib.axes._subplots.AxesSubplot at 0x1146edc18>

Count plot

In [9]:
sns.countplot(x='sex',data=titanic)
Out[9]:
<matplotlib.axes._subplots.AxesSubplot at 0x1146f3f28>

Heat maps

In [10]:
# for heat maps, indexing / correaltions needs to be established
tc = titanic.corr()
sns.heatmap(tc,cmap='coolwarm')
plt.title('titanic.corr()')
Out[10]:
Text(0.5,1,'titanic.corr()')

Facet Grid

In [11]:
g = sns.FacetGrid(data=titanic, col='sex')
g.map(sns.distplot, 'age',kde=False)
Out[11]:
<seaborn.axisgrid.FacetGrid at 0x1149473c8>