gnuplot gallery · examples/fillcrvs.lms

Filled curves

every filledcurve mode, parametric fills (gnuplot fillcrvs.dem)

Loading the WebAssembly host…

What runs

The page fetches examples/fillcrvs.bin, 2,176 bytes of lmcode bytecode (sha256 35fba4d162c0…), 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 fillcrvs.dem: "plot with filledcurves" in several variants.
mkdir("images");
mkdir("build");
p = _lmcode_ cli="lmplot" install="github:lmctl-ai/lmplot@v0.3.1";
# Image 1: the many filledcurve closing modes (x2, default, y1=, xy=, x1, y2).
plot.png("images/fillcrvs-1.png", 800, 600);
plot.cmd("set key outside");
plot.cmd("set title 'plot with filledcurve [options]'");
plot.script("plot [-10:10] [-5:3] 1.5+sin(x)/x with filledcurve x2, sin(x)/x with filledcurve, 1+sin(x)/x with lines, -1+sin(x)/x with filledcurve y1=-2, -2.5+sin(x)/x with filledcurve xy=-5,-4., -4.3+sin(x)/x with filledcurve x1, (x>3.5 ? x/3-3 : 1/0) with filledcurve y2");
plot.close();
# Image 2: intersection of two parabolas, grid drawn in front of the fills.
plot.png("images/fillcrvs-2.png", 800, 600);
plot.cmd("set key on");
plot.cmd("set grid front");
plot.cmd("set title 'Intersection of two parabolas'");
plot.cmd("plot x*x with filledcurves, 50-x*x with filledcurves, x*x with line lt 1");
plot.close();
# Image 3: parametric smiley built from filled curves, arrows and labels.
plot.png("images/fillcrvs-3.png", 700, 700);
plot.cmd("reset");
plot.cmd("set title \"Let's smile with parametric filled curves\"");
plot.script("set size square\nset key off\nunset border\nunset xtics\nunset ytics\nset grid");
plot.cmd("set arrow 1 from -0.1,0.26 to 0.18,-0.17 front size 0.1,40 lt 5 lw 4");
plot.cmd("set label 1 'gnuplot' at 0,1.2 center front");
plot.cmd("set label 2 'gnuplot' at 0.02,-0.6 center front");
plot.script("set parametric\nset xrange [-1:1]\nset yrange [-1:1.6]");
plot.script("plot [t=-pi:pi] sin(t),cos(t) with filledcurve xy=0,0 lt 15, sin(t)/8-0.5,cos(t)/8+0.4 with filledcurve lt 3, sin(t)/8+0.5,cos(t)/8+0.4 with filledcurve lt 3, t/5,abs(t/5)-0.8 with filledcurve xy=0.1,-0.5 lt 1, t/3,1.52-abs(t/pi) with filledcurve xy=0,1.8 lt -1");
plot.close();
end _lmcode_
r = run_lmcode(p);
assert(r.ok, json_stringify(r));
cp = system cp images/fillcrvs-1.png images/fillcrvs.png;
assert(cp.code == 0);
println("wrote images/fillcrvs.png (and images/fillcrvs-1.png .. images/fillcrvs-3.png)");