GEOG 30323: Data Analysis & Visualization
2026-11-03
import seaborn as sns
import pandas as pd
import matplotlib.pyplot as plt
from pandas_datareader import wb
sns.set_theme(style = "whitegrid", rc = {"figure.figsize": (10, 8)})
eu_countries = ['AT', 'BE', 'BG', 'HR', 'CY', 'CZ', 'DK', 'EE', 'FI', 'FR',
'DE', 'GR', 'HU', 'IE', 'IT', 'LV', 'LT', 'LU', 'MT', 'NL',
'PL', 'PT', 'RO', 'SK', 'SI', 'ES', 'SE']
ue = wb.download(indicator = "SL.UEM.TOTL.ZS",
country = eu_countries, start = 1991,
end = 2025)
ue.reset_index(inplace = True)
ue.columns = ['country', 'year', 'unemployment']
# Convert the year to integer for better labels
ue = ue.assign(year = ue.year.astype(int))seabornseaborn’s heatmap() function; takes a wide data frame with y-values in the index and x-values as column headersseaborn ‘heat map’seabornseaborn; available in the color_palette() functionseabornseaborn# Make a Greece-only dataset
greece = ue.query('country == "Greece"')
# Plot every country in grey, first
sns.lineplot(data = ue, x = "year", y = "unemployment",
units = "country", estimator = None,
color = "grey")
# Then, plot Greece on top
sns.lineplot(data = greece, x = "year", y = "unemployment",
hue = "country", palette = ["blue"], linewidth = 3)countries = ["Spain", "Greece", "Italy", "Germany"]
four = ue[ue["country"].isin(countries)]
sns.lineplot(data = four, x = "year", y = "unemployment",
hue = "country", hue_order = countries, legend = False)
# Label each line at its end, in the matching color
end = four.query('year == 2025').set_index('country')
for country, color in zip(countries, sns.color_palette()):
plt.text(2025.5, end.loc[country, 'unemployment'], country,
color = color, va = 'center', fontweight = 'bold')
# Make room for the labels
plt.xlim(1990, 2030)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 pltseaborn and matplotlibseaborn 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!GEOG 30323 | Data Analysis & Visualization