SPB Git

spb/wp40_uqo

Public MIT
2.2 KB · 36 lines python
1"""Journal-style figure settings (serif text, Times-like math, thin spines, grayscale-safe palette, panel labels)."""2import matplotlib3matplotlib.use("Agg")4import matplotlib.pyplot as plt5from matplotlib import rcParams67PALETTE = {"cpu1": "#8c8c8c", "cpuN": "#1a1a1a", "metal": "#b2182b", "metal_unfused": "#ef8a62", "pandas": "#999999", "polars": "#4393c3", "duckdb": "#2166ac", "raid": "#b2182b", "neutral": "#4d4d4d"}8MARK = {"cpu1": "s", "cpuN": "o", "metal": "^", "metal_unfused": "v"}9LABEL = {"cpu1": "CPU, 1 thread", "cpuN": "CPU, 18 threads", "metal": "Metal (fused)", "metal_unfused": "Metal (4 kernels)"}1011def setup():12    rcParams.update({13        "font.family": "serif", "font.serif": ["STIX Two Text", "Times New Roman", "Times", "DejaVu Serif"],14        "mathtext.fontset": "stix", "font.size": 8.5, "axes.titlesize": 9, "axes.labelsize": 8.5, "legend.fontsize": 7.5,15        "xtick.labelsize": 7.5, "ytick.labelsize": 7.5, "axes.linewidth": 0.6, "xtick.major.width": 0.5, "ytick.major.width": 0.5,16        "xtick.major.size": 2.5, "ytick.major.size": 2.5, "xtick.direction": "out", "ytick.direction": "out",17        "axes.spines.top": False, "axes.spines.right": False, "legend.frameon": False, "legend.handlelength": 1.8,18        "lines.linewidth": 1.0, "lines.markersize": 3.5, "figure.dpi": 200, "savefig.dpi": 300, "pdf.fonttype": 42,19        "axes.grid": False, "axes.prop_cycle": matplotlib.cycler(color=["#1a1a1a", "#b2182b", "#2166ac", "#4d4d4d", "#ef8a62"]),20    })2122def panel(ax, letter, title=None):23    """Panel label in the Journal-of-Finance style: 'Panel A. Title' above the axes, left-aligned."""24    t = f"Panel {letter}." + (f" {title}" if title else "")25    ax.set_title(t, loc="left", fontsize=8.5, fontweight="bold", pad=6)2627def light_grid(ax, axis="y"):28    ax.grid(True, axis=axis, color="#d9d9d9", linewidth=0.4, linestyle="-", zorder=0); ax.set_axisbelow(True)2930def ref_line(ax, y=1.0, label=None):31    ax.axhline(y, color="#4d4d4d", linewidth=0.6, linestyle=(0, (4, 2)), zorder=1)32    if label: ax.annotate(label, xy=(1.0, y), xycoords=("axes fraction", "data"), xytext=(-2, 2), textcoords="offset points", ha="right", va="bottom", fontsize=7, color="#4d4d4d")3334def fmt_elements(ax):35    ax.set_xscale("log"); ax.set_xlabel("Elements (returns)")36
Files · edf90b664f59d98f1489651599148df98a2fb1d1
Menu

Theme