gnuplot gallery · examples/fillbetween.lms
Fill between curves
area between two data curves (gnuplot fillbetween.dem)
Loading the WebAssembly host…
What runs
The page fetches examples/fillbetween.bin, 1,585 bytes of lmcode bytecode
(sha256 2bb75bfbf30b…), 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.
# Demo fillbetween.dem: fill the area between two curves (data from silver.dat).
mkdir("images");
mkdir("build");
if (!file_exists("examples/data/silver.dat")) {
mkdir("examples/data");
write_file("examples/data/silver.dat", http_get("https://raw.githubusercontent.com/lmctl-ai/lmplot/main/examples/data/silver.dat"));
}
p = _lmcode_ cli="lmplot" install="github:lmctl-ai/lmplot@v0.3.1";
# Image 1: plain filledcurves between columns 2 and 3, outlined with lines.
plot.png("images/fillbetween-1.png", 800, 600);
plot.script("set style data lines\nset xrange [10:*]\nset yrange [0:175]");
plot.cmd("set title 'Fill area between two curves'");
plot.cmd("plot 'examples/data/silver.dat' u 1:2:3 '%lf %lf %lf' w filledcu, '' u 1:2 lt -1 notitle, '' u 1:3 lt -1 notitle");
plot.close();
# Image 2: same with the pattern fill.
plot.png("images/fillbetween-2.png", 800, 600);
plot.cmd("set style fill pattern 2");
plot.cmd("set title 'Fill area between two curves (pattern fill)'");
plot.cmd("replot");
plot.close();
# Image 3: above/below colouring where the curves cross.
plot.png("images/fillbetween-3.png", 800, 600);
plot.cmd("set style fill solid 1.0 noborder");
plot.script("set xrange [250:500]\nset autoscale y");
plot.cmd("set title 'Fill area between two curves (above/below)'");
plot.cmd("plot 'examples/data/silver.dat' u 1:2:($3+$1/50.) w filledcurves above title 'Above', '' u 1:2:($3+$1/50.) w filledcurves below title 'Below', '' u 1:2 lt -1 lw 2 title 'curve 1', '' u 1:($3+$1/50.) lt 3 lw 2 title 'curve 2'");
plot.close();
end _lmcode_
r = run_lmcode(p);
assert(r.ok, json_stringify(r));
cp = system cp images/fillbetween-3.png images/fillbetween.png;
assert(cp.code == 0);
println("wrote images/fillbetween.png (and images/fillbetween-1.png .. images/fillbetween-3.png)");