#!/usr/bin/env python3
# usage: uv run owid-life-expectancy2.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"]
endYear = df["Year"].max()

filtered = df[df["Entity"].isin(countries) & (df["Year"] >= 1970)]

fig, ax = plt.subplots(figsize=(12, 5))

sns.lineplot(
    data=filtered,
    x="Year",
    y="Life expectancy",
    hue="Entity",       # one line + legend entry per country
    marker="o",
    ax=ax
)
ax.set_title(f"Life Expectancy 1970–{endYear}")
plt.tight_layout()
plt.savefig("life_expectancy.png", dpi=150)
plt.show()
