gnuplot gallery · examples/transparent.lms

Transparent fills

alpha fills and pattern fills (gnuplot transparent.dem)

Loading the WebAssembly host…

What runs

The page fetches examples/transparent.bin, 2,106 bytes of lmcode bytecode (sha256 5434e9e57700…), 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.

# Transparent filled areas: gnuplot "transparent.dem" (Ethan A Merritt).
# Image 1: opaque solid filled curves, image 2: the same with 50% transparency,
# image 3: transparent pattern-filled curves.
mkdir("images");
mkdir("build");
p = _lmcode_ cli="lmplot" install="github:lmctl-ai/lmplot@v0.3.1";
plot.cmd("set encoding utf8");
plot.cmd("set style fill solid 1.0 noborder");
plot.cmd("set style function filledcurves y1=0");
# three Gaussians defined as gnuplot user functions
plot.cmd("Gauss(x,mu,sigma) = 1./(sigma*sqrt(2*pi)) * exp( -(x-mu)**2 / (2*sigma**2) )");
plot.cmd("d1(x) = Gauss(x, 0.5, 0.5)");
plot.cmd("d2(x) = Gauss(x,  2.,  1.)");
plot.cmd("d3(x) = Gauss(x, -1.,  2.)");
plot.cmd("set xrange [-5:5]");
plot.cmd("set yrange [0:1]");
plot.cmd("unset colorbox");
plot.cmd("set key title 'Gaussian Distribution'");
plot.cmd("set key top left Left reverse samplen 1");
plot.cmd("set samples 200");
let gauss = "plot d1(x) fs solid 1.0 lc rgb 'forest-green' title 'μ =  0.5 σ = 0.5', d2(x) lc rgb 'gold' title 'μ =  2.0 σ = 1.0', d3(x) lc rgb 'dark-violet' title 'μ = -1.0 σ = 2.0'";

# --- 1: opaque ---
plot.png("images/transparent-1.png", 800, 600);
plot.cmd("set title 'Solid filled curves'");
plot.cmd(gauss);
plot.close();

# --- 2: translucent, overlaps blend ---
plot.png("images/transparent-2.png", 800, 600);
plot.cmd("set style fill transparent solid 0.5 noborder");
plot.cmd("set title 'Transparent filled curves'");
plot.cmd(gauss);
plot.close();

# --- 3: transparent patterns (the pattern background is not painted) ---
plot.png("images/transparent-3.png", 800, 600);
plot.cmd("set style fill transparent pattern 4 bo");
plot.cmd("set title 'Transparent pattern-filled curves'");
plot.cmd(gauss);
plot.close();
end _lmcode_
r = run_lmcode(p);
assert(r.ok, json_stringify(r));
cp = system cp images/transparent-3.png images/transparent.png;
assert(cp.code == 0);
println("wrote images/transparent.png (and images/transparent-1.png .. images/transparent-3.png)");