lmplot authoring skill

lmplot is a self-contained gnuplot executable and LMScript host with an embedded anti-aliased PNG rasterizer and DejaVu TrueType fonts for byte-identical PNG and SVG scientific plotting.

Purpose

Use lmplot to render 2D and 3D scientific plots, pm3d surfaces, contours, heat maps, histograms, polar and radar charts, curve fits, and statistical summaries from LMScript _lmcode_ blocks or direct gnuplot command-line invocations without X11, Cairo, libgd, or external font files.

When to use it

Choose lmplot for data visualization, mathematical function plotting, gnuplot stats and fit round-trips, multi-panel dashboards, and numbered PNG animation frames in headless containers, CI runners, or local scripts. Pair it with lmparticle, lmphysics, lmcad, or lmdraw when combining simulation data or 2D/3D schematics into composite figures.

Install

Install the lmctl CLI globally, or declare cli="lmplot" and install="github:lmctl-ai/lmplot@v0.3.1" in an LMScript _lmcode_ block so the runtime downloads and verifies the self-contained binary (Linux glibc 2.35 or newer, macOS, or Windows).

npm install -g @lmctl-ai/lmctl
lmplot --version
lmplot --notices
lmplot --lmcode-schema --json

Commands

lmplot operates both as an lmcode host invoked through run_lmcode(p) and as a complete headless gnuplot command-line tool via the lmplot gnuplot passthrough route.

lmplot --version
lmplot --notices
lmplot --lmcode-schema
lmplot --lmcode-schema --json
lmplot --lmcode-signatures
lmplot --lmcode FILE [--lmcode FILE ...]
lmplot gnuplot -e "set terminal png size 800,500; set output 'sin.png'; plot sin(x) lw 2"
lmplot gnuplot script.gp

Inputs and outputs

In _lmcode_ mode, lmplot exposes context plot: Plot alongside the standard lmcode_std_v3 catalog. All Plot methods execute immediately against a persistent in-process gnuplot session.

Safety rules

Worked examples

Plot a function and its Taylor approximation to a deterministic PNG file:

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 cubic Taylor approximation'");
plot.cmd("set xlabel 'x'; set ylabel 'y'; set grid");
plot.cmd("plot [-3.14:3.14] sin(x) lw 2 title 'sin(x)', x - x**3/6.0 dt 2 lw 2 title 'x - x^3/6'");
plot.close();
end _lmcode_
r = run_lmcode(p);
assert(r.ok, json_stringify(r));

Load an in-memory datablock, run gnuplot stats to compute a linear regression, verify the slope with plot.assert_close, and plot the data with the fitted line:

mkdir("images");
p = _lmcode_ cli="lmplot" install="github:lmctl-ai/lmplot@v0.3.1";
plot.data("pts", "1 2.1\n2 3.9\n3 6.2\n4 8.0\n5 9.9\n");
plot.cmd("stats $pts using 1:2 nooutput");
let slope = plot.num("STATS_slope");
let intercept = plot.num("STATS_intercept");
plot.assert_close(slope, 1.97, 0.05);
plot.png("images/regression.png", 800, 500);
plot.cmd("f(x) = STATS_slope * x + STATS_intercept");
plot.cmd("plot $pts using 1:2 with points pt 7 ps 1.5 title 'Data', f(x) with lines lw 2 title 'OLS fit'");
plot.close();
end _lmcode_
r = run_lmcode(p);
assert(r.ok, json_stringify(r));

Errors and exit codes

Each lmcode invocation emits a single terminal LMCODE_RETURN_BEGIN / LMCODE_RETURN_END frame. Exit code 0 indicates success. Exit code 2 indicates CLI usage errors, retired flags, or malformed invocation manifest metadata. Exit code 3 indicates bytecode load failure, any gnuplot command or expression evaluation error (reported as gnuplot: <GPVAL_ERRMSG>), a failed plot.assert_close check, an output write error, or exceeding LMPLOT_MAX_MEMORY_MB. Exit code 4 indicates an application or frame output failure.

How to verify

Check schema and signature parity against the lmscript compiler and confirm that rendering the same script twice yields byte-identical PNG files:

lmplot --version
lmplot --lmcode-schema --json > /tmp/lmplot.schema.json
lmplot --lmcode-signatures > /tmp/lmplot.sigs.txt
lmscript --lmcode-signatures /tmp/lmplot.schema.json > /tmp/lmplot.compiler.txt
diff -u /tmp/lmplot.compiler.txt /tmp/lmplot.sigs.txt