"""SCI Figure Hub — Kaplan-Meier Survival Step Curve + Risk Table (CC0-1.0)""" import numpy as np import matplotlib.pyplot as plt PALETTE = ["#E64B35", "#3C5488"] plt.rcParams.update({"font.sans-serif": ["Arial", "DejaVu Sans"], "font.size": 8, "axes.spines.top": False, "axes.spines.right": False, "pdf.fonttype": 42}) t = np.array([0, 6, 12, 18, 24, 30, 36, 48, 60]) s_high = np.array([1.00, 0.94, 0.87, 0.82, 0.76, 0.72, 0.68, 0.63, 0.60]) s_low = np.array([1.00, 0.86, 0.71, 0.58, 0.46, 0.39, 0.33, 0.27, 0.22]) risk_h = [120, 112, 101, 93, 84, 76, 68, 54, 41] risk_l = [118, 99, 80, 63, 49, 39, 31, 22, 14] fig, (ax, ax_tbl) = plt.subplots(2, 1, figsize=(3.5, 3.1), dpi=300, gridspec_kw={"height_ratios": [4, 1.1], "hspace": 0.35}) for name, s, ci, col in [("Treatment", s_high, 0.06, PALETTE[0]), ("Control", s_low, 0.07, PALETTE[1])]: ax.step(t, s, where="post", color=col, lw=1.6, label=name) ax.fill_between(t, np.clip(s - ci, 0, 1), np.clip(s + ci, 0, 1), step="post", color=col, alpha=0.14) ax.plot(t[2::2], s[2::2], "+", color=col, ms=4.5, mew=0.9) ax.text(0.04, 0.12, "Log-rank p = 0.0014\nHR = 0.48 (0.31–0.74)", transform=ax.transAxes, fontsize=7) ax.set_ylim(0, 1.05) ax.set_xlim(0, 62) ax.set_ylabel("Survival Probability") ax.legend(frameon=False, loc="upper right") ax_tbl.axis("off") ax_tbl.set_xlim(0, 62) ax_tbl.set_ylim(0, 2.2) for row_i, (lbl, counts, col) in enumerate([("Treat", risk_h, PALETTE[0]), ("Ctrl", risk_l, PALETTE[1])]): y = 1.4 - row_i * 0.9 ax_tbl.text(-3, y, lbl, ha="right", va="center", fontsize=7, color=col, fontweight="bold") for ti, c in zip(t[::2], counts[::2]): ax_tbl.text(ti, y, str(c), ha="center", va="center", fontsize=7, family="monospace") ax.set_xlabel("Follow-up Time (months)") fig.savefig("kaplan_meier.pdf", bbox_inches="tight")