SPB Git
2.3 KB · 37 lines python
1#!/usr/bin/env python32"""Figure ch21 — IPCB Montréal (Statistique Canada, tableau 18-10-0289-01, base 2023 = 100), données RÉELLES lues dans data/raw.3Séries résidentielles depuis le début de la série (T1 2017) jusqu'au T3 2026 ; non résidentiel en comparaison.4Sortie : assets/figures/ch21/ch21-fig-ipcb-montreal.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 matplotlib.pyplot as plt, matplotlib.dates as mdates9from traite.style import setup, palette, savefig, LARGEUR10import ch21_cout_neuf as cas1112ETIQ = {"Bâtiments résidentiels [621]": "Bâtiments résidentiels", "Maison individuelle [621112]": "Maison individuelle",13        "Immeuble à hauteur restreinte (moins de cinq étages) [62111]": "Immeuble < 5 étages",14        "Tour d'habitations (cinq étages ou plus) [621111]": "Tour d'habitation (≥ 5 étages)", "Bâtiments non résidentiels [622]": "Non résidentiel"}1516def main():17    setup()18    df = cas.ipcb_montreal(); df = df[df["date"] >= "2017-01-01"]19    fig, ax = plt.subplots(figsize=(LARGEUR, 3.5))20    for i, (t, lab) in enumerate(ETIQ.items()):21        s = df[df["type"] == t]22        lw = 2.2 if t.startswith("Maison") else 1.423        ls = "--" if t.startswith("Bâtiments non") else "-"24        ax.plot(s["date"], s["indice"], color=palette.cat[i], lw=lw, ls=ls, label=lab)25    ax.axhline(100, color=palette.ink2, lw=0.6, ls=":"); ax.text(df["date"].min(), 101, "2023 = 100", fontsize=7.5, color=palette.ink2)26    ax.set_ylabel("Indice (2023 = 100)"); ax.set_xlim(df["date"].min(), df["date"].max() + __import__("pandas").Timedelta(days=120))27    ax.legend(loc="upper left", bbox_to_anchor=(0.0, 0.98), fontsize=7.5)28    mi = df[df["type"] == "Maison individuelle [621112]"]29    ax.annotate(f"T3 2026 : {mi['indice'].iloc[-1]:.1f}", xy=(mi["date"].iloc[-1], mi["indice"].iloc[-1]), xytext=(-70, 14), textcoords="offset points", fontsize=7.5,30                arrowprops=dict(arrowstyle="-", color=palette.ink2, lw=0.6), color=palette.ink)31    ax.xaxis.set_major_locator(mdates.YearLocator()); ax.xaxis.set_major_formatter(mdates.DateFormatter("%Y"))32    ax.set_ylim(60, 125)33    out = savefig(fig, "ch21/ch21-fig-ipcb-montreal.pdf"); print("OK", out)3435if __name__ == "__main__":36    main()37
Files · 389e91a727c101832cccbfb4f596baebb72913c7
Menu

Theme