Getting Started & Parity
Install WasmMakie, swap over from CairoMakie for both 2D Axis and 3D Axis3 scenes, check supported recipes, and keep compiled browser plots concretely typed.
Install
WasmMakie.jl is registered in Julia's General registry and depends only on WasmTarget and Base64.
using Pkg
Pkg.add("WasmMakie")Drop-in from CairoMakie
Replace using CairoMakie with using WasmMakie. Your Figure, Axis, Axis3, nested GridLayout, Colorbar, Legend, axislegend, Label, Theme, and 2D / 3D plot recipes use the same names, defaults, and keyword arguments.
Static HTML vs WasmGC
For static pages, reports, or notebooks, save("plot.html", fig) and html_snippet(fig; hidpi = true) record the Canvas2D draw stream on the host and bundle the small JS replayer and fonts into plain HTML:
using WasmMakie
fig = Figure(size = (640, 420))
ax = Axis(fig[1, 1]; title = "Damped Sine", xlabel = "t", ylabel = "y")
xs = collect(range(0.0, 10.0; length = 200))
ys = exp.(-0.2 .* xs) .* sin.(2.0 .* xs)
lines!(ax, xs, ys; linewidth = 2.2)
# Save a standalone HTML page
save("plot.html", fig)
# Or generate an embeddable HTML fragment (set fonts = false after the first plot on a page)
snippet = html_snippet(fig; hidpi = true)For client-side recomputation in the browser, compile your plotting function with compile_figure and embed the resulting WasmGC bytes with wasm_html_snippet:
using WasmMakie
function draw_wave()
fig = Figure(size = (640.0, 420.0))
ax = Axis(fig[1, 1]; title = "Live WasmGC Plot", xlabel = "x", ylabel = "sin(x)")
xs = collect(range(0.0, 2pi; length = 120))
lines!(ax, xs, sin.(xs); color = :steelblue, linewidth = 2.5)
render!(fig, WasmCtx())
return nothing
end
wasm_bytes = compile_figure(draw_wave, ())
html = "<!doctype html><html><body>" *
wasm_html_snippet(wasm_bytes, "draw_wave"; width = 640, height = 420) *
"</body></html>"
write("live_plot.html", html)3D Axis3 Engine
Axis3 is a pure-Julia 3D engine compiled directly to WasmGC and HTML Canvas2D with zero external 3D JavaScript libraries. It implements Makie's azimuth, elevation, perspectiveness, aspect, and viewmode projection math, with z-buffered Blinn-Phong surface shading, depth-tested vector wireframes, 3D curves, 3D scatter markers, indexed meshes, and full GridLayout + Colorbar integration:
using WasmMakie
fig = Figure(size = (640, 460))
ax = Axis3(fig[1, 1]; title = "Sombrero Wave", xlabel = "x", ylabel = "y", zlabel = "z")
xs = collect(range(-4.0, 4.0; length = 35))
ys = collect(range(-4.0, 4.0; length = 35))
zs = [let r = sqrt(x^2 + y^2); r == 0.0 ? 1.0 : sin(r) / r end for x in xs, y in ys]
sf = surface!(ax, xs, ys, zs; colormap = :viridis)
wireframe!(ax, xs, ys, zs; color = (:black, 0.22), linewidth = 0.6)
Colorbar(fig[1, 2], sf; label = "sinc(r)")
save("sombrero3d.html", fig)CairoMakie 2D & 3D Parity
WasmMakie targets near 1-to-1 visual and API parity with CairoMakie across both 2D Axis and 3D Axis3 scenes. Every category below runs in pure Julia and compiles to WasmGC Canvas2D:
| Area | Supported 2D & 3D Surface |
|---|---|
| Layout & Blocks | Figure, Axis, Axis3, nested GridLayout, Colorbar, Legend (LineElement, MarkerElement, PolyElement), axislegend, Label, Box, colsize!, rowsize!, colgap!, rowgap!, Relative, Fixed, Auto, resize_to_layout! |
| 3D Axis3 & Recipes | Axis3 (azimuth, elevation, perspectiveness, aspect, viewmode, protrusions, limits!, zlims!), surface! (z-buffered Blinn-Phong shading), wireframe! / wireframe, 3D lines!, 3D scatter!, 3D mesh!, linked Colorbar, interactive pointer drag-to-orbit and wheel zoom |
| Axes, Scales & Ticks | identity, log10, log2, log, sqrt, pseudolog10, DataAspect, AxisAspect, xreversed / yreversed, LinearTicks, WilkinsonTicks, limits!, xlims!, ylims!, linkxaxes! / linkyaxes! / linkaxes!, hidedecorations!, hidespines! |
| 2D Primitives | lines!, scatter!, scatterlines!, linesegments!, poly!, band! (NaN-splitting), heatmap!, image!, mesh!, text!, arrows! / arrows2d!, bracket!, all 16 markers plus Char markers, custom dash patterns |
| Statistical & Field Recipes | barplot! (dodge, stack, horizontal), stairs!, stem!, hist!, density!, boxplot!, violin!, crossbar!, waterfall!, pie!, series!, errorbars!, rangebars!, hlines!, vlines!, hspan!, vspan!, ablines!, contour!, contourf!, spy!, ecdfplot!, plus non-mutating lines, scatter, ... variants |
| Colors, Colormaps & Themes | wong_colors(), Cycled, hex and CSS color names, (color, alpha), 25 built-in colormaps (:viridis, :plasma, :inferno, :magma, :cividis, :turbo, :RdBu, :coolwarm, :roma, :vik, ...) with Reverse and alpha; Theme, set_theme!, with_theme, theme_minimal, theme_dark, theme_black, theme_light, theme_ggplot2, theme_latexfonts |
Concrete-Type Tips for WasmGC
Static HTML replay runs in regular Julia, so any ordinary Makie code works. When you compile a plotting function or Therapy @island to WasmGC, keep types concrete so WasmTarget.jl compiles cleanly without dynamic dispatch:
- Use Float64 tuples and vectors: pass
size = (640.0, 360.0)andVector{Float64}data arrays (avoid heterogeneousVector{Any}). - Use the flat heatmap overload in WasmGC kernels:
heatmap!(ax, xs, ys, values, nx, ny)takes flat column-majorVector{Float64}values and explicitInt64dimensions for minimal generated code. - Keep colormap switches concrete: return
WasmMakie.ColormapSpec(viaWasmMakie.to_colormap_spec(:viridis)) when switching colormaps dynamically from a reactive signal. - Qualify Figure alongside HTML libraries: when pairing with Therapy.jl (which exports HTML's
Figureelement), useimport WasmMakie as WMand callWM.Figure/WM.Axis.
import WasmMakie as WM
using WasmMakie: heatmap!, lines!
function draw_field(freq::Int64)
f = Float64(freq)
fig = WM.Figure(size = (640.0, 360.0))
ax1 = WM.Axis(fig[1, 1]; title = "Wave", xlabel = "x", ylabel = "y")
xs = Float64[]
ys = Float64[]
n = Int64(100)
i = Int64(0)
while i < n
x = Float64(i) / Float64(n - Int64(1)) * 6.283185307179586
push!(xs, x)
push!(ys, sin(f * x))
i = i + Int64(1)
end
lines!(ax1, xs, ys; color = WM.Cycled(1), linewidth = 2.0)
ax2 = WM.Axis(fig[1, 2]; title = "Field", xlabel = "x", ylabel = "y")
nx = Int64(24)
ny = Int64(16)
ex = collect(range(0.0, 6.283185307179586; length = nx + Int64(1)))
ey = collect(range(0.0, 3.141592653589793; length = ny + Int64(1)))
vals = Float64[]
col = Int64(0)
while col < ny
row = Int64(0)
while row < nx
push!(
vals,
sin(f * Float64(row) / Float64(nx)) * cos(Float64(col) / Float64(ny)),
)
row = row + Int64(1)
end
col = col + Int64(1)
end
hm = heatmap!(ax2, ex, ey, vals, nx, ny; colormap = :viridis)
WM.Colorbar(fig[1, 3], hm)
WM.render!(fig, WM.WasmCtx())
return nothing
endIntentionally Out of Scope
WasmMakie stays fast and lightweight by targeting zero-dependency HTML Canvas2D from pure Julia. While both 2D Axis and 3D Axis3 scenes are first-class supported, the following Makie features remain outside scope:
- GPU volumetric & custom-shader pipelines:
LScene,volume!,volumeslices!, ray-marched shaders, and multi-million-triangle scenes belong to GPU backends (GLMakie / WGLMakie). - Makie's Observable & window-event runtime: WasmMakie does not ship Makie's in-process
Observablegraph or desktop event loop. Instead, hosts like Therapy.jl and Snapshot.jl own reactive state and trigger clean recomputations into the canvas. - Canvas2D pattern fills and runtime LaTeX parsing: hatch/pattern fills and dynamic LaTeX-after-construction are not implemented on the Canvas2D surface.