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