import seaborn as sns
import pandas as pd
import matplotlib.pyplot as plt
from pandas_datareader import wb
sns.set(style = "whitegrid", rc = {"figure.figsize": (10, 8)})
eu_countries = ['BE', 'BG', 'CZ', 'DK', 'DE', 'EE', 'IE', 'GR', 'ES', 'FR', 'HR',
'IT', 'CY', 'LV', 'LT', 'LU', 'HU', 'MT', 'NL', 'AT', 'PL', 'PT',
'RO', 'SI', 'SK', 'FI', 'SE', 'GB']
ue = wb.download(indicator = "SL.UEM.TOTL.ZS",
country = eu_countries, start = 1991,
end = 2019)
ue.reset_index(inplace = True)
ue.columns = ['country', 'year', 'unemployment']
seaborn
seaborn
’s heatmap()
function;
takes a wide data frame with x-values in the index and y-values as
column headersseaborn
‘heat map’seaborn
seaborn
; available
in the color_palette()
functionseaborn
seaborn
# Convert the year to integer for better labels
ue = ue.assign(year = ue.year.astype(int))
# Make a Greece-only dataset
greece = ue.query('country == "Greece"')
# Plot everything as grey, first
sns.lineplot(data = ue, x = "year", y = "unemployment",
hue = "country", palette = ["grey"] * 28,
legend = False)
# Then, plot Greece on top
sns.lineplot(data = greece, x = "year", y = "unemployment",
hue = "country", palette = ["blue"], linewidth = 3)
seaborn
is a wrapper around matplotlib
,
the main plotting engine for Pythonmatplotlib
customization methods are
available for your seaborn
plots - and there are many!import matplotlib.pyplot as plt
seaborn
and
matplotlib
seaborn
returns a matplotlib
object that
can be modified by the options in the pyplot
moduleseaborn
and
available as arguments - so check the documentation to see what you can
do!