SPB Git
2.8 KB · 52 lines python
1#!/usr/bin/env python32"""Figure ch44 — VAN des deux mesures selon le taux d'actualisation et la croissance du prix de l'électricité3(DONNÉES SYNTHÉTIQUES, hypothèses de analysis/python/cases/ch44_renovation.py). Cartes de chaleur divergentes centrées4sur VAN = 0 avec la courbe d'équilibre. Sortie : assets/figures/ch44/ch44-fig-heatmap-van.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 numpy as np, matplotlib.pyplot as plt9from matplotlib.colors import TwoSlopeNorm10from traite.style import setup, palette, savefig, LARGEUR11import ch44_renovation as cas1213TAUX = np.array([0.02, 0.03, 0.04, 0.0458, 0.05, 0.06, 0.07, 0.08, 0.10])14CROIS = np.array([0.0, 0.01, 0.02, 0.03, 0.04, 0.05, 0.06])151617def panneau(ax, m, titre, vmax):18    G = cas.grille_van(m, taux=tuple(TAUX), croissances=tuple(CROIS)).values19    norm = TwoSlopeNorm(vmin=-vmax, vcenter=0.0, vmax=vmax)20    # colormap divergente du traité : négatif = bleu, positif = rouge → ici on inverse pour que le positif (VAN > 0) soit bleu21    cmap = palette.cmap_div().reversed()22    ax.imshow(G, cmap=cmap, norm=norm, aspect="auto", origin="upper")23    ax.set_xticks(range(len(CROIS))); ax.set_xticklabels([f"{g*100:.0f} %" for g in CROIS])24    ax.set_yticks(range(len(TAUX))); ax.set_yticklabels([f"{r*100:.2f} %".replace(".", ",") if r == 0.0458 else f"{r*100:.0f} %" for r in TAUX])25    ax.grid(False)26    for i in range(len(TAUX)):27        for j in range(len(CROIS)):28            v = G[i, j]29            ax.text(j, i, f"{v/1000:+.1f}".replace(".", ",").replace("-", "−"), ha="center", va="center", fontsize=6.8,30                    color="white" if abs(v) > 0.55 * vmax else palette.ink)31    # courbe d'équilibre sur une grille fine (interpolée sur les indices de cellules)32    rf = np.linspace(TAUX[0], TAUX[-1], 60); gf = np.linspace(CROIS[0], CROIS[-1], 60)33    Z = np.array([[cas.flux_mesure(m, r=r, g=g)["van"] for g in gf] for r in rf])34    xi = np.interp(gf, CROIS, np.arange(len(CROIS))); yi = np.interp(rf, TAUX, np.arange(len(TAUX)))35    if (Z.min() < 0) and (Z.max() > 0):36        ax.contour(xi, yi, Z, levels=[0.0], colors=[palette.ink], linewidths=1.3)37    ax.set_xlabel("Croissance annuelle du prix de l'électricité"); ax.set_title(titre, loc="left", fontsize=9)383940def main():41    setup()42    mm = cas.mesures()43    fig, (a, b) = plt.subplots(1, 2, figsize=(LARGEUR, 3.5), gridspec_kw={"wspace": 0.30})44    panneau(a, mm["A"], "(a) Thermopompe climat froid — VAN (k$)", 10000.0)45    panneau(b, mm["B"], "(b) Isolation de l'entretoit — VAN (k$)", 4000.0)46    a.set_ylabel("Taux d'actualisation")47    out = savefig(fig, "ch44/ch44-fig-heatmap-van.pdf"); print("OK", out)484950if __name__ == "__main__":51    main()52
Files · da8a4ee0304be0aa9c54ed0aad08d985fc4539fc
Menu

Theme