gnuplot gallery · examples/contours.lms
Contours
contour lines on base and surface (gnuplot contours.dem)
Loading the WebAssembly host…
What runs
The page fetches examples/contours.bin, 1,672 bytes of lmcode bytecode
(sha256 ee8205291b60…), and hands it to the same lmplot.wasm every example uses.
The bytecode calls the host's Plot functions (plot.cmd, plot.data, plot.num,
plot.png …); gnuplot draws into an in-memory file system and the page shows the files the program wrote.
In SVG mode plot.png("x.png", w, h) writes x.svg with gnuplot's svg terminal; PNG mode uses lmplot's
own rasterizer and fonts, the same bytes as the native binary.
The program was compiled ahead of time from the source on the right with lmscript; the lmscript lines around the
_lmcode_ block (data generation, ${...} values, run_lmcode) ran at compile time.
# contours.dem: contour lines on the base grid and on the surface.
mkdir("images");
mkdir("build");
p = _lmcode_ cli="lmplot" install="github:lmctl-ai/lmplot@v0.3.1";
plot.script("set samples 20\nset isosamples 21\nset xlabel 'X axis'\nset ylabel 'Y axis'");
plot.script("set zlabel 'Z ' offset 1, 0\nset view 60, 30, 0.85, 1.1");
plot.script("set key at screen 1.0, 0.9\nset style textbox opaque noborder margins 0.5, 0.5");
# Image 1: default contours (base) under x*y.
plot.png("images/contours-1.png", 800, 600);
plot.cmd("set title 'contour plot'");
plot.cmd("set contour");
plot.cmd("splot x*y");
plot.close();
# Image 2: contour levels drawn with labels, on the base grid.
plot.png("images/contours-2.png", 800, 600);
plot.cmd("set cntrparam levels auto 10");
plot.cmd("set view 60, 30, 1.0, 1.1");
plot.cmd("set title 'contours on base grid with labels'");
plot.cmd("set contour base");
plot.cmd("set cntrlabel font ',7'");
plot.cmd("splot x**2-y**2 with lines, x**2-y**2 with labels boxed notitle");
plot.close();
# Image 3: contours on both base and surface with hidden-line removal.
plot.png("images/contours-3.png", 800, 600);
plot.cmd("set title 'contours on both base and surface'");
plot.cmd("set contour both");
plot.cmd("set hidden3d");
plot.cmd("splot x**2-y**2 with lines, x**2-y**2 with labels boxed notitle");
plot.close();
end _lmcode_
r = run_lmcode(p);
assert(r.ok, json_stringify(r));
cp = system cp images/contours-2.png images/contours.png;
assert(cp.code == 0);
println("wrote images/contours.png (and images/contours-1.png .. images/contours-3.png)");