A grammar-driven plotting library for Go: one model, many backends, runs everywhere — pure Go and cgo-free, from the core to the window.
Status:
v0.x. The model is settled and the API is not frozen. The three seams that took positional scale arguments have been reshaped so that a chart can gain a dimension additively, and the dimension has arrived:figure/threedraws a chart whose x, y and z are all data (ADR 0056, ADR 0060);v1.0.0returns when the surface settles.
The name is the thesis: a figure is a chart that has been finished and placed, and what makes it one is the model behind it rather than the file it was saved as. One specification enters figure, a spectrum of output formats comes out.
One declarative chart specification, rendered through interchangeable backends.
The core is pure Go with no dependencies at all — not "no cgo", literally
nothing outside the standard library — and emits both vector formats, SVG and
PDF. Add one module and the same specification renders to PNG and JPEG through
stilus, a sparse rasterizer with no
dependencies of its own, still with CGO_ENABLED=0.
| Dependencies | Output | |
|---|---|---|
github.com/timzifer/figure |
stdlib only | SVG, PDF, browser canvas |
github.com/timzifer/figure/backend/stilus |
stilus, go-opentype — zero CGO, Go 1.27.1 |
PNG, JPEG, an in-memory surface |
github.com/timzifer/figure/backend/window |
GoGPU (gogpu), backend/stilus — zero CGO, Go 1.27.1 |
a native window |
github.com/timzifer/figure/backend/gg |
GoGPU (gg), x/image — zero CGO |
deprecated, removed in v0.20.0 — PNG, JPEG, a surface (why) |
github.com/timzifer/figure/backend/gg/gpu |
GoGPU (gg/gpu, wgpu) — zero CGO |
deprecated, removed in v0.20.0 — gg's GPU tier |
github.com/timzifer/figure/arrow/v18 |
apache/arrow-go — zero CGO |
— (a data source) |
The browser is in the core too, because it needs nothing to be: a canvas 2D
context is reached through syscall/js, which is the standard library
(ADR 0017). Everything else is behind the
same ir.Backend interface, in a module of its own, so what a program links is
what it asked for: a server that renders SVG links nothing but the standard
library, and a desktop program that opens a window links a window layer.
The release check in CONTRIBUTING.md verifies each
module outside the development workspace before it is tagged, so a published
require line names a core that exists.
go get github.com/timzifer/figure # core: SVG and PDF, stdlib only
go get github.com/timzifer/figure/backend/stilus # raster: PNG and JPEG
go get github.com/timzifer/figure/backend/window # a native window
go get github.com/timzifer/figure/arrow/v18 # optional: plot Arrow dataGo 1.25 or newer for the core (why); 1.27.1 or newer for the raster backend and the window, whose font library requires it (ADR 0094).
package main
import (
"log"
"math"
"github.com/timzifer/figure"
"github.com/timzifer/figure/geom"
"github.com/timzifer/figure/palette"
"github.com/timzifer/figure/scale"
"github.com/timzifer/figure/theme"
)
func main() {
xs := make([]float64, 200)
ys := make([]float64, 200)
for i := range xs {
xs[i] = float64(i) / 20
ys[i] = math.Sin(xs[i])
}
p := figure.New(
figure.Theme(theme.Dark),
figure.Size(800, 400),
figure.Title("Signal"),
figure.YTitle("amplitude"),
)
p.X(scale.Linear(scale.Nice()))
p.Y(scale.Linear(scale.Nice()))
p.Add(geom.Line(
figure.Float64Columns(map[string][]float64{"x": xs, "y": ys}),
geom.X("x"), geom.Y("y"),
geom.Color(palette.Blue),
geom.Tension(0.4),
))
if err := p.Render(figure.SVG("signal.svg")); err != nil {
log.Fatal(err)
}
}For PDF or raster, swap the target — nothing else changes:
err := p.Render(figure.PDF("signal.pdf")) // still stdlib only
import stilusbackend "github.com/timzifer/figure/backend/stilus"
err := p.Render(stilusbackend.PNG("signal.png"))A runnable version is in examples/signal.
Every figure in docs/gallery.md is rendered by
backend/stilus/cmd/gallery and re-checked in CI, so a
picture cannot drift away from the code that produced it.
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
- Scales — linear, time, log, symlog, probability, ordinal. Extended-Wilkinson tick placement, calendar-unit time steps, minor ticks per decade, pinned tick sequences, probability paper.
- Marks — lines, points, bars, areas, steps, rects, boxplots, histograms, violins, ridgelines, hexbins, beeswarms, ECDFs, survival curves, trends, contours, horizons, rasters, treemaps, icicles, trees, sankeys, arcs, graphs, UpSet plots, Venn diagrams, parallel coordinates, parallel sets, nearest-neighbour partitions, error bars, intervals, text, annotations — including a locus, a family of curves given by a formula rather than by data, which is what a Nichols diagram's closed-loop contours and a Smith chart's VSWR circles are.
- Schedules — a rect on a time axis is a gantt bar;
geom.ProgressByfills it as far as the work has got, andgeom.Dependsdraws the constraints between bars in all four linkages, taking its colour from the link table so that a critical path is a column rather than a feature. - Coordinate systems — Cartesian, polar (so a bar is a pie and an icicle is a sunburst), Smith, ternary, parallel — with one axis per dimension, which is the parallel-coordinates plot — and geographic: four map projections, equal-area by default because size on a map reads as quantity, on which a scatter is a point map, a line is a route and a rect is a cell of a gridded field.
- Three dimensions —
figure/threedraws a chart whose x, y and z are all data: a surface over a grid, a trajectory through a volume, a field of bars over two categoricals. It projects above the IR, so every backend draws one; the camera is a value the caller holds, so the host owns the drag; and a scene can be looked at from several cameras at once, which is what a static export and a printed page need. - Colour and size — qualitative palettes, sequential and diverging ramps, classed ramps, a size channel, and the legend, colourbar or size key that follows from which of them a layer was handed.
- Layout — facets, subplot grids, secondary axes, guides solved by one constraint solver.
- Output — SVG and PDF from the standard library alone; PNG, JPEG and an in-memory surface through one module; a browser canvas; a native window; an opt-in GPU tier.
- Interaction — hit-testing, hover and click, zoom and pan, an overlay layer, clickable legends, linked views, keyed transitions, streaming data.
- Reading — typeset notation in labels, and a description, a data table and per-mark semantics for a reader that is not an eye.
The long version, with what each one is for and which record decided it, is in docs/features.md.
| docs/gallery.md | Every figure the library draws, rendered from the code that draws it. |
| docs/charts.md | Chart forms and the programs that produce them: categories, stacks, pies and donuts, Smith charts, edge tables, boxes, distributions, bubbles, small multiples, secondary axes, label placement. |
| docs/interaction.md | The browser, the native window, the GPU tier, live data, and a chart that follows its surface. |
| docs/scale-out.md | What happens when a chart has more rows than the screen has pixels. |
| docs/reading.md | Notation in labels, and charts that can be read without being seen. |
| docs/spec.md | A chart as JSON, and plotting Arrow data. |
| docs/features.md | The full feature surface. |
| docs/milestones.md | How each capability arrived, and the argument that shaped it. |
Your spec ──► Model ──► IR ──► Backend ──► output
───────── ───── ──── ─────── ──────
geoms scales ~8 backend/svg SVG
scales coords drawing backend/pdf PDF
coords layout ops backend/canvas browser canvas
theme ticks backend/stilus PNG / JPEG / a surface
facets panels backend/window a native window
The ir.Backend interface is the seam. Geoms never touch a renderer; a renderer
never knows what a scale is. That is what lets figure stand on a young,
fast-moving graphics stack without being welded to it — the whole gg adapter was
about 300 lines (why that matters), and
replacing it with stilus touched no geom, scale or coord
(ADR 0094).
Things ride on that seam without widening it. A render can be watched, so that
a pointer can be told which layer drew what it is over
(ADR 0015); two frames can be compared, so that
a surface repaints only what moved
(ADR 0016); and a backend that can carry
words, resize itself, or repaint part of a frame says so through an optional
interface — ir.Semantics, ir.Resizer, ir.Partial — rather than through a
method every backend would have to implement. No identity channel and no damage
channel went into the drawing interface.
The native window is the same argument once more: it is a surface that draws with the raster backend and presents the result, so there is one implementation of every mark and a window shows what a file would (ADR 0021).
- CONCEPT.md — the design document: motivation, positioning, architecture, roadmap.
- docs/adr — why each open question was answered the way it was.
- docs/chart-types.md — every chart form, what draws it today, and what the missing ones would cost.
- docs/benchmarks.md — the benchmark suite: what each benchmark measures, which numbers are gated, and the latest results.
- docs/milestones.md — how the library was built, in the order it was built, with the argument behind each step.
- pkg.go.dev — the API reference, generated from the doc comments.
- CONTRIBUTING.md — building a six-module repository, how to regenerate golden files and figures, and how a release is tagged.
- SECURITY.md — which versions get fixes, and how to report a vulnerability privately.
- CODE_OF_CONDUCT.md — what participating here looks like.
Much of figure was written with an AI assistant — Claude, in Claude Code — in the loop, under human direction and review. The design decisions and the arguments in the ADRs are the ones a human signed off on; a good deal of the typing was not. What makes that workable is the same thing the rest of this README describes: every claim here is held up by a golden file, a test or a benchmark that CI runs on every commit, so the code is checked against the behaviour rather than against a plausible-sounding explanation of it.
MIT. The core links nothing; backend/stilus links only permissively licensed
code (stilus and brotli are MIT; go-opentype, dsnet/compress and the Go fonts
it embeds are BSD-3-Clause). That is a requirement rather than a
preference — figure must be embeddable by downstream projects under any
license.








