gnuplot gallery · examples/pm3d.lms
pm3d colour surfaces
pm3d surfaces, palette, colorbox, depth order (gnuplot pm3d.dem)
Loading the WebAssembly host…
What runs
The page fetches examples/pm3d.bin, 1,944 bytes of lmcode bytecode
(sha256 59419b3f9167…), 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.
# pm3d.dem: coloured surfaces (pm3d) with a palette and colorbox.
mkdir("images");
mkdir("build");
p = _lmcode_ cli="lmplot" install="github:lmctl-ai/lmplot@v0.3.1";
plot.script("set xlabel 'x'\nset ylabel 'y'\nset key top\nset border 4095");
plot.script("set xrange [-15:15]\nset yrange [-15:15]\nset zrange [-0.25:1]");
plot.script("set samples 25\nset isosamples 20");
# Image 1: default pm3d on the radial sinc function.
plot.png("images/pm3d-1.png", 800, 600);
plot.cmd("set title 'pm3d demo. Radial sinc function. Default options.'");
plot.cmd("set pm3d; set palette");
plot.cmd("splot sin(sqrt(x**2+y**2))/sqrt(x**2+y**2)");
plot.close();
# Image 2: pm3d on surface and top (map projection), with depth ordering.
plot.png("images/pm3d-2.png", 800, 600);
plot.cmd("set title 'set pm3d at bst (depthorder, interp 2,2)'");
plot.cmd("set ticslevel 0");
plot.cmd("set cblabel 'colour gradient'");
plot.cmd("set pm3d at bst border lt -1 lw .3");
plot.cmd("set pm3d depthorder");
plot.cmd("set pm3d interp 2,2");
plot.cmd("set view 50,50");
plot.cmd("set xyplane at -0.26");
plot.cmd("unset surface");
plot.cmd("unset key");
plot.cmd("splot sin(sqrt(x**2+y**2))/sqrt(x**2+y**2)");
plot.close();
# Image 3: a gray map seen from above.
plot.png("images/pm3d-3.png", 800, 600);
plot.script("reset\nset xrange [-15:15]\nset yrange [-15:15]\nset samples 100; set isosamples 100");
plot.script("set title 'gray map'\nset view map\nset pm3d\nset palette gray\nunset surface\nunset key");
plot.cmd("splot sin(sqrt(x**2+y**2))/sqrt(x**2+y**2)");
plot.close();
end _lmcode_
r = run_lmcode(p);
assert(r.ok, json_stringify(r));
cp = system cp images/pm3d-2.png images/pm3d.png;
assert(cp.code == 0);
println("wrote images/pm3d.png (and images/pm3d-1.png .. images/pm3d-3.png)");