-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmake_figures.py
More file actions
71 lines (57 loc) · 2.67 KB
/
Copy pathmake_figures.py
File metadata and controls
71 lines (57 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
"""Regenerate the README results figure from the classification engine.
Offline: runs the engine on the bundled sample portfolio and plots (a) how far
each category sits from the 70% floor and (b) the post-exclusion carbon
intensity against the 1.5C pathway target — illustrating that the pathway is a
diagnostic, not a gate.
pip install matplotlib
python make_figures.py # writes docs/sfdr2_classification.png
"""
import os
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
from sfdr2.data import SAMPLE_PORTFOLIO
from sfdr2.alignment import assess
from sfdr2.classify import classify
from sfdr2.config import CATEGORY_FLOOR_PCT
HERE = os.path.dirname(os.path.abspath(__file__))
DOCS = os.path.join(HERE, "docs")
os.makedirs(DOCS, exist_ok=True)
YEAR = 2025
def main():
a = assess(SAMPLE_PORTFOLIO, year=YEAR)
c = classify(SAMPLE_PORTFOLIO, year=YEAR)
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(12, 4.6))
# Panel A — category qualifying weight vs the 70% floor
cats = ["Sustainable", "Transition", "ESG Basics"]
direct = [a["categories"][k]["direct_pct"] for k in cats]
meets = [a["categories"][k]["meets"] for k in cats]
colours = ["#2e6f4e" if m else "#b8bcc0" for m in meets]
ax1.bar(cats, direct, color=colours)
ax1.axhline(CATEGORY_FLOOR_PCT, color="#b5462f", ls="--", lw=1.5,
label=f"{CATEGORY_FLOOR_PCT:.0f}% category floor")
for i, v in enumerate(direct):
ax1.text(i, v + 1, f"{v:.0f}%", ha="center", va="bottom", fontsize=9)
ax1.set_ylabel("Qualifying weight (% of portfolio)")
ax1.set_ylim(0, max(100, max(direct) + 10))
ax1.set_title(f"Category test → classified: {c.label}")
ax1.legend(frameon=False, fontsize=9)
ax1.grid(alpha=0.25, axis="y")
# Panel B — carbon intensity vs the 1.5C decarbonisation pathway (diagnostic)
labels = ["Parent\n(pre-screen)", "Post-exclusion\nWACI", "1.5C pathway\ntarget"]
vals = [a["parent_intensity"], a["post_excl_waci"], a["pathway_target"]]
bcols = ["#9bb4c7", "#4a7a96", "#2e6f4e"]
bars = ax2.bar(labels, vals, color=bcols)
for b, v in zip(bars, vals):
ax2.text(b.get_x() + b.get_width() / 2, b.get_height(), f"{v:.0f}",
ha="center", va="bottom", fontsize=9)
status = "on pathway" if a["pathway_aligned"] else "NOT on pathway (reweighting required)"
ax2.set_ylabel("WACI (tCO2e / EUR m revenue)")
ax2.set_title(f"Pathway diagnostic — {status}")
ax2.grid(alpha=0.25, axis="y")
fig.tight_layout()
out = os.path.join(DOCS, "sfdr2_classification.png")
fig.savefig(out, dpi=130, bbox_inches="tight")
print("wrote", out)
if __name__ == "__main__":
main()