File size: 2,035 Bytes
f28d994
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Shared ACM double-column paper style for the figures_paper package.

Column widths follow ACM sigconf: single-column 3.25 in, double-column 6.75 in.
Fonts tuned for two-column legibility. pdf.fonttype=42 embeds TrueType (venue-safe).
"""
from pathlib import Path
import matplotlib as mpl
import matplotlib.pyplot as plt
import seaborn as sns

COL1 = 3.25   # single-column
COL2 = 6.75   # double-column

# Colorblind-safe + print-friendly. ``deep`` is the primary, ``muted`` secondary.
PALETTE = list(sns.color_palette("deep"))
MUTED = list(sns.color_palette("muted"))
COLORBLIND = list(sns.color_palette("colorblind"))


def apply():
    sns.set_theme(style="whitegrid", context="paper", font_scale=1.0)
    mpl.rcParams.update({
        "font.size": 8.5,
        "axes.labelsize": 9.0,
        "axes.titlesize": 9.5,
        "axes.titleweight": "bold",
        "xtick.labelsize": 8.0,
        "ytick.labelsize": 8.0,
        "legend.fontsize": 7.5,
        "legend.frameon": False,
        "figure.dpi": 150,
        "savefig.dpi": 300,
        "savefig.format": "pdf",
        "savefig.bbox": "tight",
        "savefig.pad_inches": 0.02,
        "pdf.fonttype": 42,
        "ps.fonttype": 42,
        "font.family": "DejaVu Sans",
        "axes.spines.top": False,
        "axes.spines.right": False,
        "axes.grid": True,
        "grid.alpha": 0.35,
        "grid.linewidth": 0.5,
        "lines.linewidth": 1.6,
    })


def ensure_dirs(root):
    root = Path(root)
    out = {}
    for sub in ("pdf", "png", "svg", "data"):
        d = root / "figures_paper" / sub
        d.mkdir(parents=True, exist_ok=True)
        out[sub] = d
    return out


def save(fig, name, out):
    """Write PDF (vector), PNG (300 dpi preview), SVG. Closes the figure."""
    fig.savefig(out["pdf"] / f"{name}.pdf")
    fig.savefig(out["png"] / f"{name}.png", dpi=300)
    fig.savefig(out["svg"] / f"{name}.svg")
    plt.close(fig)


def stat_box(ax, x, y, s, fs=8):
    ax.text(x, y, s, transform=ax.transAxes, fontsize=fs, color="dimgray")