SPB Git
2.0 KB · 34 lines python
1#!/usr/bin/env python32"""Figure ch07 — répartition des charges communes annuelles entre les huit fractions (DONNÉES SYNTHÉTIQUES).3Sortie : assets/figures/ch07/ch07-fig-repartition-charges.pdf"""4import sys, pathlib5ROOT = pathlib.Path(__file__).resolve().parents[3]6sys.path.insert(0, str(ROOT / "analysis/python")); sys.path.insert(0, str(ROOT / "analysis/python/cases"))7import numpy as np, matplotlib.pyplot as plt8from traite.style import setup, palette, savefig, LARGEUR, fmt_dollars9import ch07_servitudes_copro as cas1011def main():12    setup()13    qp = cas.quotes_parts(); A = cas.cotisation_seuil(); rep = cas.repartition_charges(A, qp)14    noms = [f"{n} ({s:.0f} m², q = {q:.4f})".replace(".", ",") for n, s, q in zip(qp["noms"], qp["superficies"], qp["q"])]15    blocs = [("Charges courantes (q_i × budget)", rep["par_fraction_courantes"], palette.cat[0]),16             ("Fonds de prévoyance (q_i × A*)", rep["par_fraction_fonds"], palette.cat[1]),17             ("Fonds d'auto assurance (q_i)", rep["par_fraction_auto"], palette.cat[2]),18             ("Stationnement à usage restreint (part égale)", rep["par_fraction_restreint"], palette.cat[3])]19    y = np.arange(len(noms)); gauche = np.zeros(len(noms))20    fig, ax = plt.subplots(figsize=(LARGEUR, 3.4))21    for lab, vals, col in blocs:22        ax.barh(y, vals, left=gauche, color=col, height=0.66, label=lab); gauche += vals23    for yi, tot in zip(y, rep["par_fraction_total"]):24        ax.text(tot + 150, yi, f"{tot:,.0f} $/an".replace(",", " "), va="center", fontsize=7.5, color=palette.ink)25    ax.set_yticks(y); ax.set_yticklabels(noms); ax.invert_yaxis()26    ax.xaxis.set_major_formatter(plt.FuncFormatter(fmt_dollars)); ax.set_xlim(0, rep["par_fraction_total"].max() * 1.25)27    ax.set_xlabel("Charges annuelles de la fraction (dollars de 2026, données synthétiques)")28    ax.grid(axis="y", visible=False)29    ax.legend(loc="upper center", bbox_to_anchor=(0.45, -0.2), ncol=2, fontsize=7.5)30    out = savefig(fig, "ch07/ch07-fig-repartition-charges.pdf"); print("OK", out)3132if __name__ == "__main__":33    main()34
Files · da8a4ee0304be0aa9c54ed0aad08d985fc4539fc
Menu

Theme