SPB Git
2.9 KB · 49 lines python
1#!/usr/bin/env python32"""Figure ch11 — matrice état × âge chronologique → âge effectif (convention déclarée de l'ouvrage, chapitre 11).3Panneau gauche : carte de chaleur de a_eff = (1 − λ) a + λ φ(c) L pour L = 60 ans, λ = 0,5 ; panneau droit : profils a_eff(a) par note.4Sortie : assets/figures/ch11/ch11-fig-matrice-age-effectif.pdf (schéma de convention, aucune donnée empirique)."""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 np9import matplotlib.pyplot as plt10from traite.style import setup, palette, savefig, LARGEUR11import ch11_inspection as cas121314def main():15    setup()16    L = cas.VIE_ECONOMIQUE17    ages = np.arange(0, 61, 1)18    etats = [1, 2, 3, 4, 5]19    M = np.array([[cas.age_effectif(a, L, e) for a in ages] for e in etats])20    fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(LARGEUR, 3.1), gridspec_kw={"width_ratios": [1.35, 1]})21    im = ax1.imshow(M, aspect="auto", origin="lower", cmap=palette.cmap_seq(), extent=[ages[0] - 0.5, ages[-1] + 0.5, 0.5, 5.5], vmin=0, vmax=L)22    ax1.set_yticks(etats); ax1.set_yticklabels([f"{e}" for e in etats])23    ax1.set_xlabel("Âge chronologique $a$ (années)"); ax1.set_ylabel("Note d'état $c$ (1 = excellent, 5 = mauvais)")24    ax1.grid(False)25    for e in etats:26        for a in (0, 15, 30, 45, 60):27            v = cas.age_effectif(a, L, e)28            ax1.text(min(max(a, 2), 58), e, f"{v:.0f}", ha="center", va="center", fontsize=7.5, color=palette.ink if v < 0.55 * L else "white")29    cb = fig.colorbar(im, ax=ax1, fraction=0.05, pad=0.03); cb.set_label("Âge effectif $a_{\\mathrm{eff}}$ (années)")30    cb.outline.set_visible(False)31    for i, e in enumerate(etats):32        ax2.plot(ages, M[i], color=palette.cat[i], label=f"état {e} (φ = {cas.PHI[e]:.2f})")33    ax2.plot(ages, ages, color=palette.ink2, lw=0.9, ls="--", label="$a_{\\mathrm{eff}} = a$")34    ax2.set_xlabel("Âge chronologique $a$ (années)"); ax2.set_ylabel("Âge effectif (années)")35    ax2.set_xlim(0, 60); ax2.set_ylim(0, 60)36    ax2.legend(fontsize=6.8, loc="upper left", ncol=1)37    # repère du sujet du cas 1 : a = 28, état 3 → 29 ans38    ax2.plot([28], [cas.age_effectif(28, L, 3)], marker="*", ms=9, color=palette.brand, ls="none")39    ax2.annotate("sujet cas 1\n(28 ans, état 3)", (28, cas.age_effectif(28, L, 3)), xytext=(33, 12), fontsize=7, color=palette.ink,40                 arrowprops=dict(arrowstyle="-", color=palette.ink2, lw=0.7))41    fig.suptitle(f"Convention : $a_{{\\mathrm{{eff}}}} = (1-\\lambda)\\,a + \\lambda\\,\\varphi(c)\\,L$, λ = {cas.LAMBDA}, L = {L:.0f} ans, bornée à [0, L]",42                 fontsize=8.5, x=0.02, ha="left", color=palette.ink)43    fig.tight_layout()44    out = savefig(fig, "ch11/ch11-fig-matrice-age-effectif.pdf"); print("OK", out)454647if __name__ == "__main__":48    main()49
Files · 4958fcec3502ce9b6da151998f7eaebf95b47bcc
Menu

Theme