gnuplot gallery · examples/surface1.lms

3D surfaces

hidden-line surfaces, labels, arrows (gnuplot surface1.dem)

Loading the WebAssembly host…

What runs

The page fetches examples/surface1.bin, 2,089 bytes of lmcode bytecode (sha256 5efd6b64295e…), 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.

# surface1.dem: 3D surfaces from a matrix (hidden3d) and from functions, with labels and arrows.
mkdir("images");
mkdir("build");
p = _lmcode_ cli="lmplot" install="github:lmctl-ai/lmplot@v0.3.1";
# Image 1: a 5x5 matrix of Z values drawn as a hidden-line wireframe.
plot.png("images/surface1-1.png", 800, 600);
plot.cmd("set title '3D surface from a grid (matrix) of Z values'");
plot.cmd("set xrange [-0.5:4.5]");
plot.cmd("set yrange [-0.5:4.5]");
plot.cmd("set grid");
plot.cmd("set hidden3d");
plot.data("grid", "5 4 3 1 0\n2 2 0 0 1\n0 0 0 1 0\n0 0 0 2 3\n0 1 2 4 3\n");
plot.cmd("splot '$grid' matrix with lines notitle");
plot.close();
# Image 2: a function surface with axis labels, a text label and arrows.
plot.png("images/surface1-2.png", 800, 600);
plot.script("reset\nset samples 21\nset isosamples 11");
plot.script("set xlabel 'X axis' offset -3,-2\nset ylabel 'Y axis' offset 3,-2\nset zlabel 'Z axis' offset -5");
plot.cmd("set title '3D surface from a function'");
plot.cmd("set label 1 'This is the surface boundary' at -10,-5,150 center");
plot.script("set arrow 1 from -10,-5,120 to -10,0,0 nohead\nset arrow 2 from -10,-5,120 to 10,0,0 nohead");
plot.script("set arrow 3 from -10,-5,120 to 0,10,0 nohead\nset arrow 4 from -10,-5,120 to 0,-10,0 nohead");
plot.script("set xrange [-10:10]\nset yrange [-10:10]\nset grid");
plot.cmd("splot x*y");
plot.close();
# Image 3: several surfaces at once, with a modified ticslevel.
plot.png("images/surface1-3.png", 800, 600);
plot.script("unset arrow\nunset label\nset ticslevel 0.0");
plot.cmd("set title '3D gnuplot demo ( ticslevel = 0.0 )'");
plot.cmd("splot x**2+y**2, x**2-y**2, x*y");
plot.close();
end _lmcode_
r = run_lmcode(p);
assert(r.ok, json_stringify(r));
cp = system cp images/surface1-2.png images/surface1.png;
assert(cp.code == 0);
println("wrote images/surface1.png (and images/surface1-1.png .. images/surface1-3.png)");