lmplot
lmplot is gnuplot packaged as a single self-contained executable and LMScript host with embedded DejaVu fonts and a deterministic PNG/SVG rasterizer. It renders 2D and 3D plots, surfaces, contours, heat maps, fits, and dashboards without X11, Cairo, or libgd.
Quick reference
npm install -g @lmctl-ai/lmctl
lmplot --version
lmplot --lmcode-schema --json
lmplot gnuplot -e "set terminal png size 800,500; set output 'sin.png'; plot sin(x) lw 2"
| Method or command | Signature or syntax | Purpose |
|---|---|---|
| plot.png / plot.svg / plot.close | plot.png(file, w, h), plot.svg(file, w, h), plot.close() | Open a deterministic PNG or SVG canvas at width x height pixels and flush/close it after plotting. |
| plot.cmd / plot.script / plot.load | plot.cmd(line), plot.script(text), plot.load(file) | Execute single-line gnuplot commands, multi-line gnuplot scripts, or external .gp files. |
| plot.data | plot.data(name, text) | Define an in-memory gnuplot datablock $name from a string with a collision-safe terminator. |
| plot.num / plot.str / plot.assert_close | plot.num(expr) -> float, plot.str(expr) -> string, plot.assert_close(a, b, tol) | Read gnuplot stats, fit, and GPVAL_* variables back into LMScript and verify tolerances. |
| lmplot gnuplot | lmplot gnuplot -e "..." | script.gp | Run the complete headless gnuplot CLI directly from the shell. |
mkdir("images");
p = _lmcode_ cli="lmplot" install="github:lmctl-ai/lmplot@v0.3.1";
plot.png("images/sine.png", 800, 500);
plot.cmd("set title 'sin(x) and a cubic fit'");
plot.cmd("plot sin(x) lw 2, x - x**3/6.0 dt 2");
plot.close();
end _lmcode_
r = run_lmcode(p);
assert(r.ok, json_stringify(r));
Run in the browser
lmplot also builds to WebAssembly. The browser demo runs all 45 standalone examples inside the page. gnuplot, the lmcode virtual machine and the 13 Plot functions are one fixed host, lmplot.wasm (4.6 MB), written once as systems code in C and C++. Each example is application code: a few kilobytes of lmcode bytecode the page loads at run time, so a new plot never needs a new wasm build.
- In the browser, plot.png(file, w, h) writes file.svg with gnuplot's svg terminal (LMPLOT_PNG_AS=svg). The PNG option uses lmplot's own rasterizer and fonts. 84 or 85 of the 92 example PNGs (depending on the platform the native build ran on) are byte-identical to the native binary's; the rest are 3D views that differ in a few pixels because each libm rounds sin and cos differently.
- Each run gets a fresh WebAssembly instance in a Worker, with the example's data files in an in-memory file system. The compiled module is reused, so a typical example runs in 30 to 250 ms.
- The examples are compiled ahead of time by lmscript, which also evaluates the lmscript code around each _lmcode_ block. Build everything from an lmplot checkout with the command below; the guide has the details.
scripts/build-web.sh build-site
Documentation pages
- Skill — authoring rules, CLI commands, inputs and outputs, safety rules, worked examples, and verification steps.
- Guide — native PNG rasterizer, embedded DejaVu font selection, stats/fit read-back loops, multi-host image compositing, and the standard lmcode_std_v3 catalog.
- Reference — complete CLI flags, Plot schema methods, built-in terminals, standard library catalog, and exit codes.
- Demo — all 45 examples running on the WebAssembly host, one live page per example.