File size: 2,911 Bytes
ff8d20f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Matplotlib style for paper figures (static PDF). Follows the project dataviz rules: categorical hues in a fixed
order per system (never cycled), one axis per chart, thin marks, recessive grid/axes, text in ink tokens, direct
labels where they help. Palette = the validated reference instance (light mode)."""
from __future__ import annotations

import matplotlib as mpl

SURFACE = "#fcfcfb"
INK = "#0b0b0b"
INK2 = "#52514e"
GRID = "#e1e0d9"
AXIS = "#c3c2b7"
# fixed categorical order (slot → hue); systems are mapped to slots by name, never by rank
CATEGORICAL = ["#2a78d6", "#eb6834", "#1baf7a", "#eda100", "#e87ba4", "#008300"]
SYSTEM_SLOT = {"B0_identity": 0, "B1_generic_paraphrase": 1, "B2": 3, "M1": 2, "M2": 4, "M3": 5}
SEQUENTIAL_BLUE = ["#cde2fb", "#9ec5f4", "#6da7ec", "#3987e5", "#256abf", "#1c5cab", "#104281"]


_ASSIGNED: dict[str, str] = {}
MARKERS = ["o", "s", "D", "^", "v", "P"]


def assign_system_colors(systems: list[str]) -> dict[str, str]:
    """Fixed, order-stable assignment: baselines keep their slots (B0 blue, B1 orange, B2 yellow); other systems take
    the remaining slots in the order given. Hues are never generated; beyond 6 systems the extra ones reuse a slot and
    must be distinguished by marker (see MARKERS) and direct labels."""
    fixed = {"B0_identity": 0, "B1_generic_paraphrase": 1}
    used = set()
    out: dict[str, str] = {}
    for s in systems:
        if s in fixed:
            out[s] = CATEGORICAL[fixed[s]]
            used.add(fixed[s])
        elif s.startswith("B2"):
            out[s] = CATEGORICAL[3]
            used.add(3)
    free = [i for i in range(len(CATEGORICAL)) if i not in used]
    k = 0
    for s in systems:
        if s not in out:
            out[s] = CATEGORICAL[free[k % len(free)]] if free else INK2
            k += 1
    _ASSIGNED.update(out)
    return out


def system_color(name: str) -> str:
    if name in _ASSIGNED:
        return _ASSIGNED[name]
    for key, slot in SYSTEM_SLOT.items():
        if name == key or name.lower().startswith(key.lower()):
            return CATEGORICAL[slot]
    return INK2


def system_marker(name: str, systems: list[str]) -> str:
    return MARKERS[systems.index(name) % len(MARKERS)] if name in systems else "o"


def apply() -> None:
    mpl.rcParams.update({
        "figure.facecolor": SURFACE, "axes.facecolor": SURFACE, "savefig.facecolor": SURFACE,
        "font.family": "sans-serif", "font.size": 9, "axes.titlesize": 10, "axes.labelsize": 9, "legend.fontsize": 8,
        "text.color": INK, "axes.labelcolor": INK2, "xtick.color": INK2, "ytick.color": INK2,
        "axes.edgecolor": AXIS, "axes.linewidth": 0.6, "axes.spines.top": False, "axes.spines.right": False,
        "axes.grid": True, "grid.color": GRID, "grid.linewidth": 0.5, "axes.axisbelow": True,
        "lines.linewidth": 1.6, "lines.markersize": 4.5, "legend.frameon": False, "pdf.fonttype": 42,
    })