gnuplot gallery · examples/candlesticks.lms
Candlesticks
candlesticks and box-and-whisker (gnuplot candlesticks.dem)
Loading the WebAssembly host…
What runs
The page fetches examples/candlesticks.bin, 1,258 bytes of lmcode bytecode
(sha256 1c4bb69887a6…), 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 candlesticks.dem: candlestick and box-and-whisker plots.
mkdir("images");
mkdir("build");
if (!file_exists("examples/data/candlesticks.dat")) {
mkdir("examples/data");
write_file("examples/data/candlesticks.dat", http_get("https://raw.githubusercontent.com/lmctl-ai/lmplot/main/examples/data/candlesticks.dat"));
}
p = _lmcode_ cli="lmplot" install="github:lmctl-ai/lmplot@v0.3.1";
plot.script("set xrange [0:11]\nset yrange [0:10]\nset boxwidth 0.2");
# Image 1: open/close states, hollow when open < close.
plot.png("images/candlesticks-1.png", 800, 600);
plot.cmd("set style fill empty");
plot.cmd("set title 'candlesticks showing both states of open/close'");
plot.cmd("plot 'examples/data/candlesticks.dat' using 1:(int($0)%3?$3:$5):2:6:(int($0)%3?$5:$3) with candlesticks title 'open < close', NaN with boxes lt 1 fs solid 1 title 'close < open'");
plot.close();
# Image 2: box-and-whisker with median bar and whisker bars.
plot.png("images/candlesticks-2.png", 800, 600);
plot.cmd("set style fill empty");
plot.cmd("set title 'box-and-whisker with median bar and whiskerbars'");
plot.cmd("plot 'examples/data/candlesticks.dat' using 1:3:2:6:5 with candlesticks lt 3 lw 2 title 'Quartiles' whiskerbars, '' using 1:4:4:4:4 with candlesticks lt -1 lw 2 notitle");
plot.close();
end _lmcode_
r = run_lmcode(p);
assert(r.ok, json_stringify(r));
cp = system cp images/candlesticks-1.png images/candlesticks.png;
assert(cp.code == 0);
println("wrote images/candlesticks.png (and images/candlesticks-1.png .. images/candlesticks-2.png)");