gnuplot gallery · examples/steps.lms
Step plots
steps, fsteps, histeps (gnuplot steps.dem)
Loading the WebAssembly host…
What runs
The page fetches examples/steps.bin, 1,226 bytes of lmcode bytecode
(sha256 e5e43f4024e6…), 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 steps.dem: steps, fsteps and histeps, and histograms via smooth frequency.
mkdir("images");
mkdir("build");
if (!file_exists("examples/data/steps.dat")) {
mkdir("examples/data");
write_file("examples/data/steps.dat", http_get("https://raw.githubusercontent.com/lmctl-ai/lmplot/main/examples/data/steps.dat"));
}
if (!file_exists("examples/data/hemisphr.dat")) {
mkdir("examples/data");
write_file("examples/data/hemisphr.dat", http_get("https://raw.githubusercontent.com/lmctl-ai/lmplot/main/examples/data/hemisphr.dat"));
}
p = _lmcode_ cli="lmplot" install="github:lmctl-ai/lmplot@v0.3.1";
# Image 1: the three step styles over the raw points.
plot.png("images/steps-1.png", 800, 600);
plot.cmd("set title 'Compare steps, fsteps and histeps'");
plot.cmd("set key left");
plot.cmd("plot [0:12][0:13] 'examples/data/steps.dat' notitle with points ps 2 pt 6, 'examples/data/steps.dat' title 'steps' with steps, 'examples/data/steps.dat' title 'fsteps' with fsteps, 'examples/data/steps.dat' title 'histeps' with histeps");
plot.close();
# Image 2: histogram built from unsorted data, drawn as filled steps.
plot.png("images/steps-2.png", 800, 600);
plot.cmd("set title \"Histogram built from unsorted data by 'smooth frequency'\"");
plot.script("set ylabel 'counts per bin'\nset xlabel 'bins'\nset key right\nset style fill solid 1.0");
plot.cmd("plot 'examples/data/hemisphr.dat' u (floor($1*20)):(1) smooth freq with fillsteps title 'with fillsteps'");
plot.close();
end _lmcode_
r = run_lmcode(p);
assert(r.ok, json_stringify(r));
cp = system cp images/steps-1.png images/steps.png;
assert(cp.code == 0);
println("wrote images/steps.png (and images/steps-1.png .. images/steps-2.png)");