Skip to content

theme

Mojo module 🡭

theme

Visual defaults for a Plot (colors, sizes, margins) as one struct with defaults, rather than optional parameters scattered across Plot’s builder methods. A theme changes how a mark looks, not what it means. Every Color field takes a dataviz.core.colors constant as readily as a Color(r, g, b): Theme(mark_color=CORNFLOWERBLUE).

scale (default 1.0) uniformly multiplies every other pixel-sized quantity render() computes (font size, margins, point radius, line width, tick length, legend layout). Pair Theme(scale=2.0) with a canvas twice the width/height to render the same chart at higher pixel density; the logical layout is identical at every scale. Separate from raster_supersample (default automatic, resolved per mark), which controls how much extra antialiasing work render()/render_facets()/ render_layers() do internally before downsampling back to that logical size – the two compose multiplicatively rather than substituting for each other; see raster_supersample’s own docstring.

color_by_sign (default False) makes Mark.BAR color negative bars mark_color_negative; Mark.WATERFALL/CANDLESTICK use that color unconditionally.

color_scale_low/color_scale_mid/color_scale_high are the three stops of the continuous color gradient (ColorScale.from_theme). The middle stop exists because interpolating two saturated, hue-opposite colors in RGB passes through a muddy gray that dominates a legend; a light neutral gray at 0.5 is what diverging colormaps like coolwarm/RdBu do.

color_ramp (empty by default) replaces all three with an arbitrary number of stops, which is what a perceptually uniform sequential map needs: Theme(color_ramp=viridis()), from dataviz.core.colormaps. Three stops are enough for a diverging scale and cannot express viridis and its family; see the field’s own docstring.

line_smoothing (default 0.0) controls how much _build_line_path (continuous.mojo) curves a Mark.LINE/AREA through its points via a Catmull-Rom-derived cubic Bezier: 0.0 is straight segments, 1.0 the full curve. Must be in [0.0, 1.0]. Mark.AREA smooths only its top edge. A non-zero value is mutually exclusive with a step interpolation – Plot.mark_line(step=...), mark_area(step=...) or mark_streamgraph(step=...) – and asking for both raises at render time, because a smoothed staircase rounds off the corners that carry its meaning; see StepStyle for the rest of that reasoning. The trap is that one Theme is usually shared across a figure, so the raise can come from a field set nowhere near the mark that grew a step.

font_family (default "sans-serif") is baked into each _TextRequest where it is built, since render_facets()/ render_layers() combine independently themed Plots into one draw pass. "sans-serif" resolves as a fontconfig generic alias on the raster path and as a CSS font-family value in SVG; a specific installed font name works in both, but a CSS fallback stack only means anything on the SVG side.

title_bold (default True) is the one default here that changes existing output; Theme(title_bold=False) uses regular-weight titles.

Structs