gnuplot gallery · examples/polar.lms

Polar plots

polar functions and grids (gnuplot polar.dem)

Loading the WebAssembly host…

What runs

The page fetches examples/polar.bin, 1,523 bytes of lmcode bytecode (sha256 8ababb2fa871…), 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.

# polar.dem: functions in polar coordinates.
mkdir("images");
mkdir("build");
p = _lmcode_ cli="lmplot" install="github:lmctl-ai/lmplot@v0.3.1";
# Image 1: a rose curve and a four-leaf pattern.
plot.png("images/polar-1.png", 800, 600);
plot.script("unset border\nset clip\nset polar\nset xtics axis nomirror\nset ytics axis nomirror");
plot.script("unset rtics\nset samples 160\nset zeroaxis\nset trange [0:2*pi]\nset key box");
plot.cmd("plot sin(4*t),cos(4*t)");
plot.close();
# Image 2: the "butterfly" curve.
plot.png("images/polar-2.png", 800, 600);
plot.cmd("butterfly(x)=exp(cos(x))-2*cos(4*x)+sin(x/12)**5");
plot.script("set trange [0:12*pi]\nset samples 800\nset title 'Butterfly'\nunset key");
plot.cmd("plot butterfly(t)");
plot.close();
# Image 3: polar grid with a filled curve above a bounding radius.
plot.png("images/polar-3.png", 800, 600);
plot.script("reset\nset polar\nset grid polar\nunset xtics\nunset ytics\nset border 0");
plot.script("set style fill solid 0.5\nset rrange [0.1 : 4]\nset size square");
plot.script("set key title 'bounding radius 2.5'\nset key outside top right samplen 0.7");
plot.cmd("plot 3.+sin(t)*cos(5*t) with filledcurve above r=2.5 notitle, 3.+sin(t)*cos(5*t) with line");
plot.close();
end _lmcode_
r = run_lmcode(p);
assert(r.ok, json_stringify(r));
cp = system cp images/polar-2.png images/polar.png;
assert(cp.code == 0);
println("wrote images/polar.png (and images/polar-1.png .. images/polar-3.png)");