#!/usr/bin/env python3 """Figure ch44 — flux annuels des deux mesures énergétiques du sujet du cas 1 (DONNÉES SYNTHÉTIQUES, hypothèses déclarées dans analysis/python/cases/ch44_renovation.py) : coût net à t = 0, économies annuelles croissantes et cumul actualisé. Sortie : assets/figures/ch44/ch44-fig-flux.pdf""" import sys, pathlib ROOT = pathlib.Path(__file__).resolve().parents[3] sys.path.insert(0, str(ROOT / "analysis/python")); sys.path.insert(0, str(ROOT / "analysis/python/cases")) import numpy as np, matplotlib.pyplot as plt from traite.style import setup, palette, savefig, LARGEUR, fmt_dollars import ch44_renovation as cas def panneau(ax, fl, titre, couleur): t = np.arange(len(fl["flux"])) ax.bar(t[0], fl["flux"][0], color=palette.ink2, width=0.8, label="Coût net (t = 0)") ax.bar(t[1:], fl["flux"][1:], color=couleur, width=0.8, label="Économie annuelle") ax.plot(t, fl["cumul_actualise"], color=palette.ink, lw=1.4, ls="--", marker="o", ms=2.5, label="Cumul actualisé") ax.axhline(0, color=palette.ink2, lw=0.6) ax.set_title(titre, loc="left", fontsize=9) ax.set_xlabel("Année"); ax.yaxis.set_major_formatter(plt.FuncFormatter(fmt_dollars)) ax.annotate(f"VAN {fmt_dollars(fl['van'])}".replace("-", "−"), xy=(t[-1], fl["cumul_actualise"][-1]), xytext=(4, -22 if fl["van"] < 0 else 10), textcoords="offset points", ha="right", va="top" if fl["van"] < 0 else "bottom", fontsize=8, color=palette.ink) def main(): setup() mm = cas.mesures() fa, fb = cas.flux_mesure(mm["A"]), cas.flux_mesure(mm["B"]) fig, (a, b) = plt.subplots(1, 2, figsize=(LARGEUR, 3.2), gridspec_kw={"wspace": 0.32, "width_ratios": [1, 1.35]}) panneau(a, fa, "(a) Thermopompe climat froid (15 ans)", palette.cat[0]) panneau(b, fb, "(b) Isolation de l'entretoit (31 ans)", palette.cat[1]) a.set_ylim(-13500, 2500); b.set_ylim(-2600, 600) h, l = a.get_legend_handles_labels(); fig.legend(h, l, loc="lower center", ncol=3, bbox_to_anchor=(0.5, -0.08), frameon=False) out = savefig(fig, "ch44/ch44-fig-flux.pdf"); print("OK", out) if __name__ == "__main__": main()