import seaborn as sns
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
# Loading the datasets to be used in this lab
titanic = sns.load_dataset('titanic')
fmri = sns.load_dataset('fmri')
tips = sns.load_dataset('tips')
flights = sns.load_dataset('flights')
titanic.head()
fmri.head(3)
tips.head(3)
flights.head(3)
sns.scatterplot(data=titanic, x='age', y='fare')
sns.scatterplot(data=titanic, x='age', y='fare', hue='sex')
sns.scatterplot(data=titanic, x='age', y='fare', hue='sex', style='sex')
plt.figure(figsize=(8,6))
sns.scatterplot(data=titanic, x='age', y='fare', hue='sex', style='pclass')
plt.figure(figsize=(8,6))
markers = {1:'P', 2:'X', 3:'D'} # P, X, and D are markers
sns.scatterplot(data=titanic, x='age', y='fare', hue='sex', style='pclass', markers=markers)
sns.scatterplot(data=titanic, x='age', y='fare', hue='sex', size='sex', sizes=(20,200))
sns.scatterplot(data=titanic, x='age', y='fare', hue='sex', size='pclass', sizes=(20,200))
sns.relplot(data=flights, x='month', y='passengers', kind='line')
sns.relplot(data=flights, x='year', y='passengers', kind='line')
sns.set_theme(style="darkgrid") #setting the grid for all next plots
sns.relplot(data=flights, x='month', y='passengers', ci=None, kind='line')
sns.relplot(data=flights, x='month', y='passengers', ci='sd', kind='line')
sns.relplot(data=flights, x='month', y='passengers', ci=None, estimator=None, kind='line')
sns.relplot(data=fmri, x='timepoint', y='signal',
hue='event', kind='line')
sns.relplot(data=fmri, x='timepoint', y='signal',
hue='event', kind='line', style='event')
sns.relplot(data=fmri, x='timepoint', y='signal', hue='event', kind='line',
style='event', dashes=False, markers=True)
sns.relplot(x='total_bill', y='tip', hue='smoker',
col='time', data=tips);
sns.relplot(x='timepoint', y='signal', hue='subject',
col='region', row='event', height=4,
kind='line', estimator=None, data=fmri)
sns.displot(titanic['age'])
sns.displot(titanic['age'], kde=False, bins=10)
sns.histplot(tips, x='day', shrink=.8)
sns.displot(titanic, x='age',hue='pclass')
sns.histplot(titanic, x="age",hue="sex")
sns.histplot(titanic, x="age",hue="survived")
sns.histplot(titanic, x='age',hue='pclass', multiple='stack')
sns.jointplot(data=tips, x='total_bill', y='tip')
sns.jointplot(data=tips, x='total_bill', y='tip', kind='hex')
sns.jointplot(data=tips, x='total_bill', y='tip', kind='kde', hue='day')
sns.jointplot(data=tips, x='total_bill', y='tip', kind='reg')
sns.jointplot(data=tips, x='total_bill', y='tip', kind='resid')
sns.pairplot(titanic)
sns.pairplot(tips)
sns.rugplot(data=tips, x='total_bill', y='tip')
sns.relplot(data=tips, x='total_bill', y='tip')
sns.rugplot(data=tips, x='total_bill', y='tip')
sns.kdeplot(data=tips, x='tip')
sns.kdeplot(data=tips, x='tip', hue='day')
sns.displot(titanic,x='age', kind='kde', hue='sex')
sns.kdeplot(data=tips, x='tip', hue='day', multiple='stack')
sns.displot(data=tips, x='tip', hue='day', kind='kde', fill=True)
sns.displot(titanic, x='age', kind='ecdf')
sns.catplot(data=titanic, x='sex', y='survived', hue='pclass', kind='bar')
sns.barplot(data=tips, x='sex', y='total_bill', palette='rocket', hue='day')
sns.countplot(data=tips, x='day', palette='coolwarm')
#sns.catplot(data=tips, x='day', kind='count', palette='coolwarm') will do the same
sns.pointplot(data=titanic, x='sex', y='survived', hue='class', palette='dark')
sns.boxplot(data=tips, x='day', y='total_bill')
sns.catplot(data=tips, x='day', y='total_bill', hue='smoker', kind='box')
sns.catplot(data=tips, x='day', y='total_bill', hue='smoker', kind='boxen')
sns.violinplot(data=tips, x='day', y='total_bill', palette='autumn')
# split parameter save space when hue have two levels
sns.catplot(data=tips, x='total_bill', y='day',
hue='sex', kind='violin', split=True)
# strip is the default kind paremeter when using catplot()
sns.catplot(data=tips, x='day', y='total_bill')
sns.stripplot(data=tips, x='day', y='total_bill', jitter=False)
sns.swarmplot(data=tips, x='day', y='total_bill')
sns.catplot(data=tips, x='total_bill', y='day', hue='sex', kind='swarm')
sns.catplot(data=tips, x='day', y='total_bill', hue='smoker',
col='time', kind='swarm')
sns.lmplot(data=tips, x='total_bill', y='tip')
sns.lmplot(data=tips, x='total_bill', y='tip', hue='sex')
tips['big_tip'] = (tips.tip / tips.total_bill) >.15
tips.head()
sns.lmplot(x='age', y='survived', data=titanic, logistic=True, y_jitter=0.03)
sns.lmplot(x='age', y='alone', data=titanic, logistic=True, y_jitter=0.03, hue='sex')
sns.lmplot(x='age', y='survived', data=titanic, hue='sex', logistic=True,
y_jitter=0.03, markers=['s','D'])
sns.lmplot(data=tips, x='total_bill', y='tip', hue='smoker', col='time')
sns.lmplot(data=tips, x='total_bill', y='tip', hue='smoker', col='time', row='sex')
sns.jointplot(data=tips, x='total_bill', y='tip', kind='reg')
sns.pairplot(tips, x_vars=['total_bill', 'size'], y_vars=['tip'],
hue='time', kind='reg', height=5)
plot = sns.FacetGrid(tips, col='sex', hue='smoker')
plot.map(sns.scatterplot,'total_bill', 'tip')
plot.add_legend()
plot = sns.FacetGrid(tips, col='day', height=5, aspect=.5)
plot.map(sns.barplot, 'sex', 'total_bill');
plot = sns.PairGrid(tips)
plot.map(sns.scatterplot)
plot = sns.PairGrid(tips, hue='sex')
plot.map_diag(sns.histplot)
plot.map_offdiag(sns.scatterplot)
plot.add_legend()
plot = sns.PairGrid(tips)
plot.map_diag(sns.histplot)
plot.map_upper(sns.scatterplot)
plot.map_lower(sns.kdeplot)
plot.add_legend()
plot = sns.PairGrid(tips, vars=['total_bill', 'tip'], hue='day')
plot.map(sns.scatterplot)
plot.add_legend()
sns.pairplot(tips)
sns.pairplot(tips, hue='sex', height=5);
sns.set_theme()
data = np.random.randn(10,15)
sns.heatmap(data)
titanic.head()
# Finding the correlation of features in titanic dataset
correlation = titanic.corr()
correlation
sns.heatmap(correlation)
sns.heatmap(correlation, annot=True)
sns.clustermap(correlation)
sns.set_style('whitegrid')
sns.catplot(data=tips, x='day', y='total_bill', kind='bar')
sns.set_style('dark')
sns.catplot(data=tips, x='day', y='total_bill', kind='box')
sns.set_style('white')
sns.catplot(data=tips, x='day', y='total_bill', kind='boxen')
sns.set_style('ticks')
sns.catplot(data=tips, x='day', y='total_bill', kind='box')
sns.catplot(data=tips, x='day', y='total_bill', kind='box')
sns.despine()
sns.catplot(data=tips, x='day', y='total_bill', kind='violin')
sns.despine(offset=10, trim=True)
plt.figure(figsize=(10,8))
sns.histplot(data=tips, x='total_bill', hue='sex')
sns.set_theme()
sns.set_context('paper')
sns.kdeplot(data=tips, x='tip', hue='day')
sns.set_context('talk')
sns.kdeplot(data=tips, x='tip', hue='day')
sns.set_context('poster')
sns.kdeplot(data=tips, x='tip', hue='day')
sns.set_context('notebook')
sns.kdeplot(data=tips, x='tip', hue='day')
sns.set_palette('rocket')
sns.kdeplot(data=tips, x='tip', hue='day', multiple='stack')
sns.set_palette('viridis')
sns.kdeplot(data=tips, x='tip', hue='day', multiple='stack')
sns.kdeplot(data=tips, x='tip', hue='day', multiple='stack', palette='icefire')
# To see what the palette looks like
sns.color_palette('tab10')
sns.color_palette('dark')
sns.set_theme(style='white', context='talk', palette='viridis')
sns.kdeplot(data=tips, x='tip', hue='day', multiple='stack')