SPB Git
2.5 KB · 43 lines python
1#!/usr/bin/env python32"""Figure ch42 — prix médians Centris des copropriétés et des unifamiliales par territoire, T3 2026 (DONNÉES RÉELLES, citées).3Source : APCIQ, Statistiques résidentielles Centris, 3e trimestre 2026 (communiqué du 14 octobre 2026 ; sources/notes-E.md, tableau ch. 4) ;4les chiffres sont reproduits tels que publiés (valeurs ponctuelles avec attribution ; aucun tableau APCIQ n'est reproduit).5Sortie : assets/figures/ch42/ch42-fig-medianes-rmr.pdf"""6import sys, pathlib7ROOT = pathlib.Path(__file__).resolve().parents[3]8sys.path.insert(0, str(ROOT / "analysis/python"))9import numpy as np, matplotlib.pyplot as plt10from traite.style import setup, palette, savefig, LARGEUR, fmt_dollars1112# (territoire, médiane copropriété $, variation a/a %, médiane unifamiliale $, variation a/a %) — APCIQ T3 202613DONNEES = [14    ("Province", 400_000, 0, 500_000, 2),15    ("RMR Montréal", 435_000, 2, 645_500, 2),16    ("Île de Montréal", 477_500, 1, 811_000, 2),17    ("RMR Québec", 334_900, 6, 463_500, 2),18    ("RMR Gatineau", 297_450, -5, 480_000, -3),19    ("RMR Sherbrooke", 327_000, 4, 490_750, 7),20    ("RMR Trois-Rivières", 287_000, None, 395_000, 8),21]2223def main():24    setup()25    noms = [d[0] for d in DONNEES]; copro = np.array([d[1] for d in DONNEES], float); unif = np.array([d[3] for d in DONNEES], float)26    y = np.arange(len(noms)); h = 0.3827    fig, ax = plt.subplots(figsize=(LARGEUR, 3.6))28    ax.barh(y - h / 2, copro, height=h, color=palette.cat[0], label="Copropriété (médiane Centris, T3 2026)")29    ax.barh(y + h / 2, unif, height=h, color=palette.cat[1], label="Unifamiliale (médiane Centris, T3 2026)")30    for yi, c, u, d in zip(y, copro, unif, DONNEES):31        var = "" if d[2] is None else f"  ({d[2]:+d} % a/a)".replace("+", "+").replace("-", "−")32        ax.text(c + 8000, yi - h / 2, f"{c:,.0f} $".replace(",", " ") + var, va="center", fontsize=7.3, color=palette.ink)33        ax.text(u + 8000, yi + h / 2, f"{u:,.0f} $".replace(",", " ") + f"  (ratio {c / u:.0%})", va="center", fontsize=7.3, color=palette.ink2)34    ax.set_yticks(y); ax.set_yticklabels(noms); ax.invert_yaxis()35    ax.xaxis.set_major_formatter(plt.FuncFormatter(fmt_dollars)); ax.set_xlim(0, unif.max() * 1.32)36    ax.set_xlabel("Prix médian des ventes Centris, 3e trimestre 2026 (dollars courants)")37    ax.grid(axis="y", visible=False)38    ax.legend(loc="upper center", bbox_to_anchor=(0.45, -0.18), ncol=2, fontsize=7.5)39    out = savefig(fig, "ch42/ch42-fig-medianes-rmr.pdf"); print("OK", out)4041if __name__ == "__main__":42    main()43
Files · 031fae1bd368de12dc60ff542f1be9a8fd73e699
Menu

Theme