Skip to content
Polytope

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
0.300.450.600.750.90020406080100Model AModel BModel C
Data table
EpochModel AModel BModel C
00.4400.3600.340
100.5920.4770.520
200.6890.5630.620
300.7510.6270.674
400.7910.6740.704
500.8160.7100.720
600.8320.7360.729
700.8420.7550.734
800.8490.7690.737
900.8530.7800.738
1000.8550.7880.739
astro
<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>
PropEffect
titleWhat the chart shows, as a statement or a question
subtitleUnits, sample, or how to read it
legendSeries: { label, slot, shape }. Shown for two or more series.
sourceWhere the data comes from
table slotThe same numbers as a table, behind a toggle

With D3 or Observable Plot

Read colors from the custom properties so charts follow the theme:

js
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

astro
<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.

accuracy epoch
HTML
<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.

smalllargeaccuracywide netnarrow net
Figure 3.Accuracy rises with the network's size, faster for the wide net.
astro
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.