Skip to content

ontometer_corpus.paper.figstyle

The look of every research figure: type, sizes, colour roles and small helpers.

Shared by every figure module, so a registry or a cluster keeps its colour everywhere.

Type matches the papers' body text: Latin Modern Roman with Computer Modern mathtext, 7 pt labels and 6 pt ticks at true LNCS widths. Matplotlib can embed only TrueType outlines cleanly in PDF, so the system's Latin Modern OpenType files are converted once into the user cache directory (CACHE_DIR) (a private, renamed build; DejaVu Serif when Latin Modern is not installed). Glyphs Latin Modern lacks fall back to DejaVu Serif per glyph.

Colour follows the GrowGraph brand: ink #293241, blue #224777 and orange #E67E22. The blue enters the categorical palette one step lighter (#2a5f9e), because the brand blue is too dark and too grey to carry identity as a fill; it stays as the dark end of the sequential ramp.

Colour has four roles, never mixed:

registry categorical, by registry size, the first seven registries in palette order and the rest folded into one neutral "other"; in a scatter (every pair of colours on screen together) only the first three keep a hue. The two largest closed communities, LOV and OBO, take the brand blue and orange. status outcome states (fetch failed, parse failed, skipped), only where the figure is about outcomes, always with a legend label. cluster a four-hue set that separates every pair, for k-means clusters. kind any other small categorical set (reuse kinds, fitted distributions).

Reference and median lines are muted ink; text on a filled mark takes the ink that contrasts with the fill (:func:ink_on).

Attributes

FULL = 4.8 module-attribute

HALF = 2.35 module-attribute

CATEGORICAL_PALETTE = ['#2a5f9e', '#1baf7a', '#E67E22', '#6250d6', '#e87ba4', '#008300', '#eda100', '#e34948'] module-attribute

REGISTRY_SLOTS = 7 module-attribute

SCATTER_SLOTS = 3 module-attribute

OTHER = 'other registries' module-attribute

CLUSTER_PALETTE = ['#2a5f9e', '#eda100', '#008300', '#e87ba4'] module-attribute

KIND_PALETTE = CATEGORICAL_PALETTE[:3] module-attribute

BRAND_BLUE = '#224777' module-attribute

BRAND_ORANGE = '#E67E22' module-attribute

SEQUENTIAL_CMAP = LinearSegmentedColormap.from_list('ontometer_seq', ['#f4f6fa', BRAND_BLUE]) module-attribute

DIVERGING_CMAP = LinearSegmentedColormap.from_list('ontometer_div', ['#2a5f9e', '#f2f1ec', '#9a4c0c']) module-attribute

STATUS_GOOD = '#0ca30c' module-attribute

STATUS_WARNING = '#fab219' module-attribute

STATUS_SERIOUS = '#ec835a' module-attribute

STATUS_CRITICAL = '#d03b3b' module-attribute

INK = '#293241' module-attribute

TEXT_MUTED = '#5b6475' module-attribute

NEUTRAL = '#c3c7cf' module-attribute

NEUTRAL_LIGHT = '#e6e8ec' module-attribute

SURFACE = '#ffffff' module-attribute

CACHE_DIR = Path(os.environ.get('XDG_CACHE_HOME') or Path.home() / '.cache') / 'ontometer-corpus' module-attribute

FONT_CACHE = CACHE_DIR / 'fonts' module-attribute

TEXT_FAMILY = 'OntoMeter LM Roman' module-attribute

Functions:

style()

Draw off-screen with the rcParams every paper figure uses (scripts, not notebooks).

Source code in ontometer_corpus/paper/figstyle.py
def style() -> None:
    """Draw off-screen with the rcParams every paper figure uses (scripts, not notebooks)."""
    plt.switch_backend("Agg")
    plt.rcdefaults()
    plt.rcParams.update(
        {
            # A family list, so a glyph Latin Modern lacks falls back per glyph.
            "font.family": _text_fonts(),
            "mathtext.fontset": "cm",
            "axes.formatter.use_mathtext": True,
            "font.size": 7,
            "axes.titlesize": 7,
            "axes.labelsize": 7,
            "xtick.labelsize": 6,
            "ytick.labelsize": 6,
            "legend.fontsize": 6,
            "legend.title_fontsize": 6,
            "legend.frameon": False,
            "legend.handlelength": 1.2,
            "legend.handletextpad": 0.4,
            "legend.borderaxespad": 0.2,
            "axes.titlelocation": "left",
            "axes.titlepad": 3,
            "axes.labelpad": 2,
            "axes.edgecolor": NEUTRAL,
            "axes.labelcolor": INK,
            "axes.linewidth": 0.6,
            "axes.spines.top": False,
            "axes.spines.right": False,
            "axes.grid": False,
            "text.color": INK,
            "xtick.color": TEXT_MUTED,
            "ytick.color": TEXT_MUTED,
            "xtick.labelcolor": INK,
            "ytick.labelcolor": INK,
            "xtick.major.width": 0.6,
            "ytick.major.width": 0.6,
            "xtick.minor.width": 0.4,
            "ytick.minor.width": 0.4,
            "xtick.major.size": 2.5,
            "ytick.major.size": 2.5,
            "xtick.minor.size": 1.5,
            "ytick.minor.size": 1.5,
            "xtick.major.pad": 2,
            "ytick.major.pad": 2,
            "lines.linewidth": 1.0,
            "patch.linewidth": 0,
            "axes.facecolor": SURFACE,
            "figure.facecolor": SURFACE,
            "savefig.facecolor": SURFACE,
            "pdf.fonttype": 42,
            "ps.fonttype": 42,
            "savefig.bbox": "tight",
            "savefig.pad_inches": 0.02,
        }
    )

registry_groups(order, slots=REGISTRY_SLOTS)

Registry -> the group it is drawn as: itself for the first slots, else OTHER.

Source code in ontometer_corpus/paper/figstyle.py
def registry_groups(order: list[str], slots: int = REGISTRY_SLOTS) -> dict[str, str]:
    """Registry -> the group it is drawn as: itself for the first ``slots``, else ``OTHER``."""
    return {r: (r if i < slots else OTHER) for i, r in enumerate(order)}

registry_colors(order, slots=REGISTRY_SLOTS)

Group -> colour, for the groups :func:registry_groups makes (OTHER neutral).

Source code in ontometer_corpus/paper/figstyle.py
def registry_colors(order: list[str], slots: int = REGISTRY_SLOTS) -> dict[str, str]:
    """Group -> colour, for the groups :func:`registry_groups` makes (``OTHER`` neutral)."""
    colors = {r: CATEGORICAL_PALETTE[i] for i, r in enumerate(order[:slots])}
    colors[OTHER] = NEUTRAL
    return colors

cluster_color(c)

Source code in ontometer_corpus/paper/figstyle.py
def cluster_color(c: int) -> str:
    return CLUSTER_PALETTE[c % len(CLUSTER_PALETTE)]

tint(color, amount)

color mixed toward the surface: 0 keeps the colour, 1 is the surface.

Source code in ontometer_corpus/paper/figstyle.py
def tint(color: str, amount: float) -> str:
    """``color`` mixed toward the surface: 0 keeps the colour, 1 is the surface."""
    surface = to_rgb(SURFACE)
    return matplotlib.colors.to_hex(
        [c + (s - c) * amount for c, s in zip(to_rgb(color), surface, strict=True)]
    )

ink_on(fill)

White or dark ink, whichever contrasts more with fill (WCAG contrast ratio).

Source code in ontometer_corpus/paper/figstyle.py
def ink_on(fill) -> str:
    """White or dark ink, whichever contrasts more with ``fill`` (WCAG contrast ratio)."""
    lum = _luminance(fill if isinstance(fill, str) else matplotlib.colors.to_hex(fill))
    on_white = 1.05 / (lum + 0.05)
    on_dark = (lum + 0.05) / (_luminance(INK) + 0.05)
    return SURFACE if on_white > on_dark else INK

panel(ax, letter, title)

A panel title, left-aligned, with its letter in bold.

Source code in ontometer_corpus/paper/figstyle.py
def panel(ax, letter: str | None, title: str) -> None:
    """A panel title, left-aligned, with its letter in bold."""
    label = f"$\\bf{{({letter})}}$ {title}" if letter else title
    ax.set_title(label, loc="left")

reference_line(ax, value, axis='x', **kwargs)

A dotted muted line marking a median or a threshold.

Source code in ontometer_corpus/paper/figstyle.py
def reference_line(ax, value: float, axis: str = "x", **kwargs) -> None:
    """A dotted muted line marking a median or a threshold."""
    line = ax.axvline if axis == "x" else ax.axhline
    line(value, linestyle=(0, (1, 1.5)), linewidth=0.9, color=INK, zorder=3, **kwargs)

save(fig, out, name)

<name>.pdf (no creation date, so reruns are byte-stable) and a 300 dpi PNG.

Source code in ontometer_corpus/paper/figstyle.py
def save(fig, out: Path, name: str) -> None:
    """``<name>.pdf`` (no creation date, so reruns are byte-stable) and a 300 dpi PNG."""
    fig.savefig(out / f"{name}.pdf", metadata={"CreationDate": None, "ModDate": None})
    fig.savefig(out / f"{name}.png", dpi=300)

fmt_int(v)

Source code in ontometer_corpus/paper/figstyle.py
def fmt_int(v: float) -> str:
    return f"{int(round(v)):,}".replace(",", "{,}")

fmt_pct(v)

Source code in ontometer_corpus/paper/figstyle.py
def fmt_pct(v: float) -> str:
    return f"{v:.1f}\\%"

fmt_dec(v, digits=2)

Source code in ontometer_corpus/paper/figstyle.py
def fmt_dec(v: float, digits: int = 2) -> str:
    return f"{v:.{digits}f}"

fmt_p(v)

A p-value: three decimals, or an upper bound below 0.001.

Source code in ontometer_corpus/paper/figstyle.py
def fmt_p(v: float) -> str:
    """A p-value: three decimals, or an upper bound below 0.001."""
    return "< 0.001" if v < 0.001 else f"= {v:.3f}"