Seaborn is a Python visualization library based on matplotlib. It provides a high-level interface for drawing attractive statistical graphics.
In [2]:
import pandas as pd
%matplotlib inline
import random
import matplotlib.pyplot as plt
import seaborn as sns
In [4]:
df = pd.read_csv('data/eu_trade_sums.csv')
In [108]:
df.head(10)
Out[108]:
In [6]:
yrs = [str(yr) for yr in range(2002,2016)]
In [7]:
df = df.set_index('geo')
In [12]:
uk_eu = df[(df['trade_type'] == 'Export') &
(df['partner'] == 'EU28')].loc[['EU28', 'UK']][yrs].T
In [13]:
uk_eu.plot()
Out[13]:
In [14]:
sns.lmplot('EU28', 'UK', data=uk_eu, fit_reg=False)
Out[14]:
In [50]:
uk_eu_trade = df[(df['trade_type'] == 'Export') &
(df['partner'] == 'EU28')].loc['UK'][yrs].T
In [83]:
uk_eu_trade.name = "UK-EU"
In [84]:
uk_eu_trade = uk_eu_trade.astype(int)
In [85]:
uk_eu_trade.plot()
Out[85]:
In [49]:
uk_noneu_trade = df[(df['trade_type'] == 'Export') &
(df['partner'] == 'EXT_EU28')].loc['UK'][yrs].T
In [86]:
uk_noneu_trade.name = "UK-Non-EU"
In [87]:
uk_noneu_trade
Out[87]:
In [68]:
uk_noneu_trade = uk_noneu_trade.astype(int)
In [69]:
uk_noneu_trade.plot()
Out[69]:
In [88]:
p = sns.kdeplot(uk_eu_trade, uk_noneu_trade)
p.set(xlabel='UK to EU28', ylabel='UK to Non-EU28', title="UK Trade from 2002-2016")
Out[88]:
In [71]:
sns.distplot(uk_eu_trade)
Out[71]:
In [72]:
sns.distplot(uk_noneu_trade)
Out[72]:
In [73]:
plt.hist(uk_noneu_trade, alpha=.3)
sns.rugplot(uk_noneu_trade);
In [106]:
sns.boxplot(pd.concat([uk_eu_trade, uk_noneu_trade], axis=1))
Out[106]:
In [105]:
sns.violinplot(pd.concat([uk_eu_trade, uk_noneu_trade], axis=1), orient="v")
Out[105]:
In [107]:
h = sns.heatmap(pd.concat([uk_eu_trade, uk_noneu_trade], axis=1), annot=False)
h.set(title="UK Trade from 2002-2016")
Out[107]:
In [101]:
sns.clustermap(pd.concat([uk_eu_trade, uk_noneu_trade], axis=1))
Out[101]:
In [ ]: