In [1]:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
In [2]:
#help(sns.set_context)
In [3]:
titanic = sns.load_dataset('titanic')
print(titanic.head())
In [4]:
sns.barplot(x = titanic['sex'], y = titanic['survived'] )
plt.show()
In [5]:
sns.barplot(x = 'sex', y = 'survived', data = titanic )
plt.show()
In [6]:
sns.barplot(x = titanic.sex, y = titanic.survived )
plt.show()
In [7]:
sns.barplot(x = 'sex', y = 'survived', hue = 'class', data = titanic)
plt.show()
In [8]:
sns.barplot(x = 'sex', y = 'survived', hue = 'class', data = titanic,
palette = 'hls',
order = ['male', 'female'],
capsize = 0.05,
saturation = 8,
errcolor = 'gray', errwidth = 2
)
plt.show()
In [9]:
kwargs = {'alpha':0.9, 'linestyle':':', 'linewidth':5, 'edgecolor':'k'}
sns.barplot(x = 'sex', y = 'survived', hue = 'class', data = titanic, **kwargs)
plt.show()
In [10]:
sns.set()
plt.figure(figsize = (8,6))
sns.barplot(x = 'sex', y = 'survived', hue = 'class', data = titanic, alpha =1, linestyle = "-.", linewidth = 3, edgecolor = "k")
plt.title("Barplot of Titanic Gender and Survived", fontsize = 20)
plt.xlabel("Gender", fontsize = 15)
plt.ylabel("Survived", fontsize = 15)
plt.savefig("output/barplot.png")
plt.show()
In [11]:
sns.set_context('paper')
crashes = sns.load_dataset('car_crashes').sort_values('total', ascending = False)
crashes.head()
Out[11]:
In [12]:
f, ax = plt.subplots(figsize = (6,15))
sns.set_color_codes('pastel')
sns.barplot(x = 'total', y = 'abbrev', data = crashes,
label = 'Total', color = 'b', edgecolor = 'w')
plt.show()
In [13]:
sns.set_color_codes('muted')
sns.barplot(x = 'alcohol', y = 'abbrev', data = crashes,
label = 'Alcohol-involved', color = 'b', edgecolor = 'w')
ax.legend(ncol = 2, loc = 'lower right')
sns.despine(left = True, bottom = True)
plt.show()
In [14]:
sns.set_context('paper')
tips = sns.load_dataset('tips')
sns.barplot(x = 'day', y = 'total_bill', hue = 'sex', data = tips,
palette = 'Blues', edgecolor = 'w')
tips.groupby(['day','sex']).mean()
plt.show()
In [15]:
sns.set_context('paper')
# load dataset
titanic = sns.load_dataset('titanic')
print(titanic.head())
In [16]:
# create plot
sns.countplot(x = 'class', hue = 'who', data = titanic, palette = 'magma')
plt.title('Survivors')
plt.show()