gnuplot gallery · examples/errorbars.lms

Error bars

x/y error bars, boxxyerror, log axis (gnuplot errorbars.dem)

Loading the WebAssembly host…

What runs

The page fetches examples/errorbars.bin, 1,374 bytes of lmcode bytecode (sha256 875cb92f1b4c…), 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 errorbars.dem: x/y error bars on the battery.dat measurements vs. a theory curve.
mkdir("images");
mkdir("build");
if (!file_exists("examples/data/battery.dat")) {
  mkdir("examples/data");
  write_file("examples/data/battery.dat", http_get("https://raw.githubusercontent.com/lmctl-ai/lmplot/main/examples/data/battery.dat"));
}
p = _lmcode_ cli="lmplot" install="github:lmctl-ai/lmplot@v0.3.1";
plot.script("set xlabel 'Resistance [Ohm]'\nset ylabel 'Power [W]'\nn(x)=1.53**2*x/(5.67+x)**2");
# Image 1: both x and y errors.
plot.png("images/errorbars-1.png", 800, 600);
plot.cmd("set title 'error represented by xyerrorbars'");
plot.cmd("plot [0:50] 'examples/data/battery.dat' t 'Power' with xyerrorbars, n(x) t 'Theory' w lines");
plot.close();
# Image 2: boxes instead of bars.
plot.png("images/errorbars-2.png", 800, 600);
plot.cmd("set title 'error represented by boxxyerror'");
plot.cmd("plot [0:50] 'examples/data/battery.dat' t 'Power' with boxxyerr, n(x) t 'Theory' w lines");
plot.close();
# Image 3: y errors only, log scaled y axis, small bar ends.
plot.png("images/errorbars-3.png", 800, 600);
plot.script("set logscale y\nset bars small");
plot.cmd("set title 'yerrorbars in log scale, small bars'");
plot.cmd("plot [0:50] 'examples/data/battery.dat' u 1:2:4 t 'Power' w yerr, n(x) t 'Theory' w lines");
plot.close();
end _lmcode_
r = run_lmcode(p);
assert(r.ok, json_stringify(r));
cp = system cp images/errorbars-1.png images/errorbars.png;
assert(cp.code == 0);
println("wrote images/errorbars.png (and images/errorbars-1.png .. images/errorbars-3.png)");