#!/usr/bin/env python3
# usage: uv run owid-life-expectancy3.py
# 
# requirements: matplotlib, pandas, seaborn

import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt

url = "https://ourworldindata.org/grapher/life-expectancy.csv"
df = pd.read_csv(url, storage_options={"User-Agent": "Mozilla/5.0"})
countries = ["France", "United States", "Germany", "United Kingdom"]
filtered = df[df["Entity"].isin(countries) & (df["Year"] >= 1970)]
germany = filtered[filtered["Entity"] == "Germany"]
fig, ax = plt.subplots(figsize=(12, 5))

# Band across all countries (no line, just the shaded area)
sns.lineplot(
    data=filtered,
    x="Year",
    y="Life expectancy",
    errorbar=("pi", 100),
    err_kws={"alpha": 0.2},   # band transparency
    color="steelblue",
    linewidth=0,               # suppress the mean line
    ax=ax
)

# Germany as a distinct line on top
sns.lineplot(
    data=germany,
    x="Year",
    y="Life expectancy",
    color="crimson",
    label="Germany",
    marker="o",
    ax=ax
)

ax.set_title("Life Expectancy - Germany vs. UK, US and France")
plt.tight_layout()
plt.savefig("life-expectancy.png", dpi=150)
plt.show()
