spb/traite-evaluation-qc
Public
1#!/usr/bin/env python32"""Figure ch04 — Indice des prix des logements neufs (IPLN), total maison et terrain, déc. 2016 = 100, janvier 2010 → septembre 2026 :3Montréal, Québec, Gatineau (partie du Québec), Sherbrooke, Trois-Rivières, Canada. DONNÉES RÉELLES : Statistique Canada, tableau 18-10-0205-01.4Sortie : assets/figures/ch04/ch04-fig-ipln-rmr.pdf"""5import sys, pathlib6ROOT = pathlib.Path(__file__).resolve().parents[3]7sys.path.insert(0, str(ROOT / "analysis/python")); sys.path.insert(0, str(ROOT / "analysis/python/cases"))8import pandas as pd, matplotlib.pyplot as plt, matplotlib.dates as mdates9from traite.style import setup, palette, savefig, LARGEUR10import ch04_marches as cas1112ORDRE = ["Montréal", "Québec", "Gatineau (partie du Québec)", "Sherbrooke", "Trois-Rivières", "Canada"]1314def main():15 setup()16 df = cas.ipln(); df = df[(df["composante"] == "Total") & (df["date"] >= "2010-01-01")]17 fig, ax = plt.subplots(figsize=(LARGEUR, 3.6))18 for i, geo in enumerate(ORDRE):19 s = df[df["geo"] == geo]20 ls = "--" if geo == "Canada" else "-"; lw = 2.0 if geo == "Montréal" else 1.421 ax.plot(s["date"], s["indice"], color=palette.cat[i], ls=ls, lw=lw, label=geo.replace(" (partie du Québec)", " (partie QC)"))22 dy = {"Canada": 2.3, "Trois-Rivières": -2.0}.get(geo, 0.0)23 ax.text(s["date"].iloc[-1] + pd.Timedelta(days=60), s["indice"].iloc[-1] + dy, f"{s['indice'].iloc[-1]:.1f}".replace(".", ","), fontsize=7, va="center", color=palette.ink)24 ax.axhline(100, color=palette.ink2, lw=0.6, ls=":"); ax.text(pd.Timestamp("2010-02-01"), 101.5, "déc. 2016 = 100", fontsize=7.5, color=palette.ink2)25 ax.axvspan(pd.Timestamp("2020-03-01"), pd.Timestamp("2022-12-31"), color=palette.grid, alpha=0.5, lw=0)26 ax.text(pd.Timestamp("2020-04-15"), 72, "mars 2020 –\ndéc. 2022", fontsize=7, color=palette.ink2)27 ax.set_ylabel("Indice (déc. 2016 = 100)"); ax.set_xlim(pd.Timestamp("2010-01-01"), pd.Timestamp("2027-06-01")); ax.set_ylim(70, 170)28 ax.xaxis.set_major_locator(mdates.YearLocator(2)); ax.xaxis.set_major_formatter(mdates.DateFormatter("%Y"))29 ax.legend(loc="upper left", ncol=2, fontsize=7.5)30 out = savefig(fig, "ch04/ch04-fig-ipln-rmr.pdf"); print("OK", out)3132if __name__ == "__main__":33 main()34