Download htr/evaluation/plotstyle.py from spboucher04/htr-tiny: direct link, hf CLI and curl.
- Browser
- Download file 2.91 kB
-
https://huggingface.co/spboucher04/htr-tiny/resolve/main/htr/evaluation/plotstyle.py
- Command line
-
hf download hf://spboucher04/htr-tiny/htr/evaluation/plotstyle.py
-
curl -L -o plotstyle.py https://huggingface.co/spboucher04/htr-tiny/resolve/main/htr/evaluation/plotstyle.py
2.91 kB
| """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, | |
| }) | |