graphnetz.plotting¶
Figure helpers and the two palettes:
BRAND_COLORSis the project's identity palette — a nine-step neutral ramp, light to dark — used by this site, the logo, and now the figures.NATURE_COLORSselects and orders seven of those steps for plot series.
The two used to be independent, so that restyling the site could not change a
published figure. They now share the ramp, which means the guarantee has to come
from somewhere else: NATURE_COLORS names its steps explicitly rather than
slicing BRAND_COLORS programmatically, so adding or reordering an identity
colour cannot silently repaint a figure — a figure's colours only change when
this tuple is edited.
Ordering carries the weight that hue used to. The first four steps all clear 4.5:1 against the page, because a series colour also tints markers and, in a critical-difference diagram, the model labels themselves; the three lightest steps come last and are reached only by a plot with five or more series, where they appear as bar fills stroked in ink. Luminance is a weaker cue than hue, so prefer a marker or a direct label over colour alone when a series must be identified at a glance.
Palettes¶
plotting
¶
Publication-ready matplotlib helpers.
The defaults follow figures guidelines: sans-serif Helvetica/Arial, generous single-/double-column widths, thin axes, no top/right spines, restrained categorical palette, vector output at 600 dpi.
Attributes:
| Name | Type | Description |
|---|---|---|
BRAND_COLORS |
dict[str, str]
|
The project's identity palette: a nine-step neutral ramp, light to dark. |
NATURE_COLORS |
tuple[str, ...]
|
Series colours: seven steps of |
NATURE_RC |
dict[str, object]
|
|
COLUMN_INCHES |
dict[str, float]
|
|
BRAND_COLORS
module-attribute
¶
BRAND_COLORS: dict[str, str] = {
"bright_snow": "#f8f9fa",
"platinum": "#e9ecef",
"alabaster_grey": "#dee2e6",
"pale_slate": "#ced4da",
"pale_slate_2": "#adb5bd",
"slate_grey": "#6c757d",
"iron_grey": "#495057",
"gunmetal": "#343a40",
"carbon_black": "#212529",
}
The project's identity palette: a nine-step neutral ramp, light to dark.
Used by the documentation theme and the logo so the website and the repository read as one thing. Being a symmetric ramp, it inverts cleanly between the two colour schemes; contrast against the two end steps decides each role:
| Colour | Hex | On bright_snow |
On carbon_black |
|---|---|---|---|
carbon_black |
#212529 |
14.6:1 | — |
gunmetal |
#343a40 |
10.9:1 | — |
iron_grey |
#495057 |
7.8:1 | — |
slate_grey |
#6c757d |
4.5:1 | 3.3:1 |
pale_slate_2 |
#adb5bd |
2.0:1 | 7.4:1 |
pale_slate |
#ced4da |
1.4:1 | 10.3:1 |
alabaster_grey |
#dee2e6 |
1.2:1 | 11.9:1 |
platinum |
#e9ecef |
1.1:1 | 13.0:1 |
bright_snow |
#f8f9fa |
— | 14.6:1 |
slate_grey is the pivot: the only step that clears 4.5:1 on light and 3:1
on dark, so it serves as muted prose in the light scheme and as borders and
icons in the dark one. The three darkest steps are body text on light and the
four lightest are body text on dark; each is surfaces-only on the other side.
NATURE_COLORS
module-attribute
¶
NATURE_COLORS: tuple[str, ...] = (
"#212529",
"#6c757d",
"#343a40",
"#495057",
"#adb5bd",
"#ced4da",
"#dee2e6",
)
Series colours: seven steps of BRAND_COLORS, text-safe steps first.
Drawn from the identity ramp so figures, the documentation and the logo read as one thing. A monochrome palette gives up hue, which is what normally separates series, and the ordering has to earn that back without making anything illegible.
The first four steps all clear 4.5:1 against the page, because a series colour is not only a fill: it tints a 4 pt marker and, in a critical-difference diagram, the model's own label. The light half of the ramp cannot do either job --- at 2.0:1 and below a label is unreadable and a marker vanishes --- so those three steps come last and are reached only by a plot with five or more series, where they appear as bar fills stroked in ink.
Two consequences follow. Fills from the light half need that dark outline or they
have no boundary on the page, which is why plot_grouped_bars strokes in ink
rather than in white. And luminance is a weaker cue than hue, so anything that
must be read per-series at a glance should carry a marker or a label as well,
never colour alone.
NATURE_RC
module-attribute
¶
NATURE_RC: dict[str, object] = {
"font.family": "sans-serif",
"font.sans-serif": ["Helvetica", "Arial", "DejaVu Sans"],
"mathtext.fontset": "stixsans",
"font.size": 9.5,
"text.color": _INK,
"axes.labelsize": 9.5,
"axes.titlesize": 10.5,
"axes.titleweight": "normal",
"axes.titlelocation": "left",
"axes.titlepad": 8.0,
"axes.labelpad": 4.5,
"axes.edgecolor": _INK,
"axes.labelcolor": _INK,
"xtick.labelsize": 8.5,
"ytick.labelsize": 8.5,
"xtick.color": _INK,
"ytick.color": _INK,
"legend.fontsize": 8.5,
"axes.linewidth": 0.7,
"axes.spines.top": False,
"axes.spines.right": False,
"xtick.major.width": 0.7,
"ytick.major.width": 0.7,
"xtick.major.size": 3.2,
"ytick.major.size": 3.2,
"xtick.major.pad": 3.0,
"ytick.major.pad": 3.0,
"xtick.minor.visible": False,
"ytick.minor.visible": False,
"xtick.direction": "out",
"ytick.direction": "out",
"lines.linewidth": 1.4,
"lines.markersize": 4.0,
"grid.color": "#dee2e6",
"grid.linewidth": 0.5,
"legend.frameon": False,
"legend.handlelength": 1.6,
"legend.handletextpad": 0.5,
"legend.columnspacing": 1.2,
"legend.borderaxespad": 0.6,
"savefig.dpi": 600,
"savefig.bbox": "tight",
"savefig.pad_inches": 0.05,
"savefig.transparent": False,
"figure.dpi": 150,
"figure.figsize": (COLUMN_INCHES["single"], COLUMN_INCHES["single"] / 1.45),
"pdf.fonttype": 42,
"ps.fonttype": 42,
}
Figure helpers¶
plotting
¶
Publication-ready matplotlib helpers.
The defaults follow figures guidelines: sans-serif Helvetica/Arial, generous single-/double-column widths, thin axes, no top/right spines, restrained categorical palette, vector output at 600 dpi.
Functions:
| Name | Description |
|---|---|
set_plot_style |
Apply the rcParams and color cycle. |
figure |
Create a sized figure. |
save_figure |
Save |
panel_label |
Add a bold panel label ( |
pretty_metric |
Map a history metric key ( |
set_plot_style
¶
figure
¶
figure(
width: str | float = "single",
aspect: float = 1.45,
nrows: int = 1,
ncols: int = 1,
**kwargs: object,
) -> tuple[Figure, ndarray | Axes]
Create a sized figure.
width is either "single", "double" or a float in inches.
Source code in src/graphnetz/plotting.py
save_figure
¶
save_figure(
fig: Figure,
path: str | Path,
formats: Sequence[str] = ("pdf", "png"),
dpi: int = 600,
) -> list[Path]
Save fig to one path stem in multiple formats; returns the saved paths.
Source code in src/graphnetz/plotting.py
panel_label
¶
Add a bold panel label (a, b, ...) to an axis.
Source code in src/graphnetz/plotting.py
pretty_metric
¶
Map a history metric key ("test_acc") to an axis label ("Test accuracy").
Plot builders¶
plotting
¶
Publication-ready matplotlib helpers.
The defaults follow figures guidelines: sans-serif Helvetica/Arial, generous single-/double-column widths, thin axes, no top/right spines, restrained categorical palette, vector output at 600 dpi.
Functions:
| Name | Description |
|---|---|
plot_history |
Plot a training history dict. |
plot_grouped_bars |
Grouped bar chart from a |
plot_history
¶
plot_history(
history: Mapping[str, Sequence[float]],
ax: Axes | None = None,
title: str | None = None,
std: Mapping[str, Sequence[float]] | None = None,
legend_loc: str = "best",
) -> tuple[Figure, Axes]
Plot a training history dict.
loss-keys go on the primary axis; metric-keys on a twin axis with
dashed lines. std (optional) provides per-epoch standard deviation
rendered as a translucent band.
Source code in src/graphnetz/plotting.py
plot_grouped_bars
¶
plot_grouped_bars(
values: Mapping[str, Mapping[str, float]],
errors: Mapping[str, Mapping[str, float]] | None = None,
ax: Axes | None = None,
title: str | None = None,
ylabel: str = "metric",
annotate: bool = True,
legend_loc: str = "outside bottom",
legend_ncol: int | None = None,
) -> tuple[Figure, Axes]
Grouped bar chart from a {group: {series: value}} mapping.
Optional errors of the same shape draws symmetric error bars.
Source code in src/graphnetz/plotting.py
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 | |