mosaickit: domain-neutral diagram scenes and rendering
A domain-neutral Python toolkit for assembling two-dimensional diagrams.
from mosaickit import (
Canvas,
Fill,
FillLayer,
MarkerLayer,
PathLayer,
Stroke,
TextLayer,
quadrant_axes,
)
canvas = Canvas().extend(quadrant_axes(10, 10))
canvas.add(
FillLayer(
[(1, 1), (1, 7), (8, 1)],
fill=Fill(color="#377EB8", opacity=0.12),
z_index=-1,
)
)
canvas.add(
PathLayer(
[(1, 8), (2, 5), (4, 3), (7, 1.5), (9, 1)],
stroke=Stroke(color="#984EA3", width=2),
)
)
canvas.add(MarkerLayer([(4, 3)]))
canvas.add(TextLayer((4, 3), "A", offset=(8, 8)))
canvas.save("diagram.svg")
Features
-
Small scene graph
PathLayer,FillLayer,MarkerLayer,TextLayer,ArrowLayer,LegendLayerandGroupLayer. -
Labels that cover nothing
RegionLabelLayerandPointLabelLayerplace labels clear of the drawing, with axis marks, notes and braces. -
Axes helpers
quadrant_axes(),crosshair_axes()andbox_frame()set up common frames. -
Styles and themes
Styles, themes and palettes, with colours that can be given by name.
-
Parameters and grids
Parameters and expressions,
CanvasGridlayouts and parameter sweeps. -
Pluggable rendering
A built-in Matplotlib renderer for PNG, SVG and PDF, and a
Rendererprotocol for other backends.
Scope
mosaickit owns domain-neutral scene composition, styles, themes, parameter binding, grid layout, renderer contracts and static output. Domain semantics belong to the packages built on it. Curve construction and native TikZ path generation belong to geometry packages such as bezierkit.
Install
Requires Python 3.10 or later. See Installation for extras and the development setup, or go straight to the Quick start.
Documentation
The following chapters cover mosaickit 1.0.0rc6.
- Introduction
- Installation
- Quick start
- Canvases and scenes
- Layers and axes
- Axis annotations
- Layout geometry
- Region and point labels
- Styles and colors
- Themes and configuration
- Parameters and grids
- Rendering
- Proofs
- Change history
Examples
The scripts that draw the figures in the manual and on these pages come as one zip, sorted by topic.