"""SCI Figure Hub — Bland-Altman Method Agreement Plot (CC0-1.0)""" PALETTE = ["#4DBBD5", "#3C5488", "#E64B35"] import numpy as np import matplotlib.pyplot as plt plt.rcParams.update({"font.sans-serif": ["Arial", "DejaVu Sans"], "font.size": 8, "axes.spines.top": False, "axes.spines.right": False, "pdf.fonttype": 42}) rng = np.random.default_rng(14) m1 = rng.uniform(20, 120, 65) m2 = m1 + rng.normal(1.2, 3.8, 65) mean = (m1 + m2) / 2 diff = m2 - m1 bias, sd = diff.mean(), diff.std(ddof=1) hi, lo = bias + 1.96 * sd, bias - 1.96 * sd fig, ax = plt.subplots(figsize=(3.5, 2.5), dpi=300) ax.axhspan(lo, hi, color=PALETTE[0], alpha=0.10) ax.axhline(bias, color=PALETTE[1], lw=1.3) ax.axhline(hi, ls="--", color=PALETTE[2], lw=1.0) ax.axhline(lo, ls="--", color=PALETTE[2], lw=1.0) ax.scatter(mean, diff, s=20, color=PALETTE[1], alpha=0.78, edgecolors="#FFFFFF", lw=0.4) ax.text(122, hi + 0.4, f"+1.96 SD: {hi:.2f}", ha="right", fontsize=6.8, color=PALETTE[2]) ax.text(122, bias + 0.4, f"Bias: {bias:.2f}", ha="right", fontsize=6.8, color=PALETTE[1]) ax.text(122, lo - 1.4, f"-1.96 SD: {lo:.2f}", ha="right", fontsize=6.8, color=PALETTE[2]) ax.set_xlabel("Mean of Two Methods") ax.set_ylabel("Difference (Method B - Method A)") fig.tight_layout() fig.savefig("bland_altman.pdf", bbox_inches="tight")