Charts
A frame for charts drawn by any library: title, legend, plot, data table, source.
Experimental May change in any minor version before 1.0.
In this chapter 15 pages
Validation accuracy by epoch
Synthetic example data
- Model A
- Model B
- Model C
Data table
| Epoch | Model A | Model B | Model C |
|---|---|---|---|
| 0 | 0.440 | 0.360 | 0.340 |
| 10 | 0.592 | 0.477 | 0.520 |
| 20 | 0.689 | 0.563 | 0.620 |
| 30 | 0.751 | 0.627 | 0.674 |
| 40 | 0.791 | 0.674 | 0.704 |
| 50 | 0.816 | 0.710 | 0.720 |
| 60 | 0.832 | 0.736 | 0.729 |
| 70 | 0.842 | 0.755 | 0.734 |
| 80 | 0.849 | 0.769 | 0.737 |
| 90 | 0.853 | 0.780 | 0.738 |
| 100 | 0.855 | 0.788 | 0.739 |
<Chart title="Validation accuracy by epoch" subtitle="Five seeds, shaded band is one standard deviation"
legend={[{ label: "GCN", shape: "line" }, { label: "SCN", shape: "line" }]} source="Source: our runs, 2026">
<svg>...</svg> <!-- D3, Observable Plot, or hand-drawn -->
<table slot="table" class="ply-table">...</table>
</Chart>| Prop | Effect |
|---|---|
title | What the chart shows, as a statement or a question |
subtitle | Units, sample, or how to read it |
legend | Series: { label, slot, shape }. Shown for two or more series. |
source | Where the data comes from |
table slot | The same numbers as a table, behind a toggle |
With D3 or Observable Plot
Read colors from the custom properties so charts follow the theme:
const css = getComputedStyle(document.documentElement);
const series = Array.from({ length: 8 }, (_, i) => css.getPropertyValue(`--ply-viz-${i + 1}`).trim());
Plot.plot({
color: { range: series },
style: { fontFamily: "var(--ply-font-text)", background: "transparent" },
marks: [Plot.lineY(data, { x: "epoch", y: "acc", stroke: "model", strokeWidth: 2 })],
});Static exports (paper figures) should use the token module instead, so the colors are fixed: import { viz } from "@dario-loi/polytope/tokens".
Charts in the margin
A small chart drawn for the margin shows at its own size, so its text matches the sidenotes next to it. Put .ply-chart--margin on the chart: it is at most 21rem wide, its text is 14px, and in a narrow column it shrinks and keeps that size where a plain chart keeps its 32rem width and scrolls. It has no scroll hint, since it never scrolls.
Accuracy by epoch
Synthetic example data
<Chart class="ply-chart--margin" title="..." subtitle="...">
<svg viewBox="0 0 300 140">...</svg>
</Chart>Plots saved as SVG
A plot from matplotlib, R, or another tool can go into the page as inline SVG (not as an img), so its colors follow the theme. Write the file with currentColor for ink and var(--ply-viz-1) to var(--ply-viz-8) for the series, keep the text as real text, and wrap it in .ply-plot. Both themes then use one file. --ply-plot-max caps the width at the figure's own size. Give the svg a role="img" and an aria-label that says what the plot shows.
<div class="ply-plot" style="--ply-plot-max: 28rem">
<svg viewBox="0 0 280 120" role="img" aria-label="Two series rising over ten steps; the first ends higher.">
<path d="M10 110 H270 M10 110 V10" fill="none" stroke="currentColor" stroke-width="1.2" />
<path d="M10 100 L70 80 L130 60 L190 38 L250 22" fill="none" stroke="var(--ply-viz-1)" stroke-width="2" />
<path d="M10 104 L70 94 L130 82 L190 70 L250 60" fill="none" stroke="var(--ply-viz-2)" stroke-width="2" />
<text x="12" y="22" font-size="11">accuracy</text>
<text x="214" y="104" font-size="11">epoch</text>
</svg>
</div>PlotSvg frames such a file as a numbered figure at the text's width. It caps the width at the figure's own size (the SVG's pt width), sets role="img" with your alt, and keeps the text as text for readers and crawlers. Read the file as text at build time (import svg from "./plot.svg?raw"); the SVG is trusted markup. Switch the theme to see both series change.
import svg from "./plot.svg?raw";
<PlotSvg svg={svg} alt="Accuracy against network size, two nets." num={3}>
<Fragment slot="caption">What the plot shows, then how to read it.</Fragment>
</PlotSvg>From Python, polytope_theme.mpl.save_inline_svg(fig, "plot.svg") writes that file from a figure drawn under use("light"). The ink color becomes currentColor, the muted ink, the grid, and the ground become var(--ply-color-text-muted), var(--ply-color-rule), and var(--ply-color-bg), and the eight series colors become var(--ply-viz-1) to var(--ply-viz-8), each with its light value as the fallback. Text stays text, and the background is transparent. inline_svg(fig) returns the string.
Tooltip and legend
.ply-tooltip is the black hover card used above; .ply-legend lists series with a dot, line, or bar key. .ply-texture adds a diagonal hatch for print and forced-colors mode.
The color rules live in Foundations: Charts.