gnuplot gallery · examples/rotate_labels.lms
Text boxes and rotated labels
boxed and rotated labels (gnuplot textbox.dem, rotate_labels.dem)
Loading the WebAssembly host…
What runs
The page fetches examples/rotate_labels.bin, 3,492 bytes of lmcode bytecode
(sha256 328b53db0537…), 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.
# Text boxes and rotated/coloured labels: gnuplot "textbox.dem" + "rotate_labels.dem".
# Image 1: 'with labels boxed' (two textbox styles) over line plots.
# Image 2: 'with labels rotate variable tc variable' with a datablock built in the DSL.
mkdir("images");
mkdir("build");
if (!file_exists("examples/data/table.dat")) {
mkdir("examples/data");
write_file("examples/data/table.dat", http_get("https://raw.githubusercontent.com/lmctl-ai/lmplot/main/examples/data/table.dat"));
}
p = _lmcode_ cli="lmplot" install="github:lmctl-ai/lmplot@v0.3.1";
# --- 1: textboxes (two side by side panels via multiplot) ---
plot.png("images/rotate_labels-1.png", 1000, 500);
plot.cmd("set grid");
plot.cmd("unset xtics");
plot.cmd("set xrange [ -0.50 : 12.00 ]");
plot.cmd("set yrange [ 30.00 : 110.0 ]");
plot.cmd("set bmargin 3");
plot.cmd("set border back");
plot.cmd("unset key");
plot.cmd("set style textbox 1 opaque border lc 'blue'");
plot.cmd("set style textbox 2 opaque margins 6,1.5 fc 'grey75' border lc black");
plot.cmd("set multiplot layout 1,2");
plot.cmd("set title 'textboxes with blue border'");
plot.cmd("plot 'examples/data/table.dat' using 0:2 title column with lines lw 3, '' using 0:2:2 with labels center boxed bs 1 notitle column");
plot.cmd("set title 'larger textboxes with grey fill'");
plot.cmd("plot 'examples/data/table.dat' using 0:2 title column with lines lw 3, '' using 0:2:2 with labels center boxed bs 2 notitle column");
plot.cmd("unset multiplot");
plot.close();
# --- 2: rotation angle and colour taken from data columns ---
# A DSL loop builds one datablock row per number word: "x text angle".
fn name(i: int) -> string {
let w = "twelve";
switch (i) {
case 1: { w = "one"; }
case 2: { w = "two"; }
case 3: { w = "three"; }
case 4: { w = "four"; }
case 5: { w = "five"; }
case 6: { w = "six"; }
case 7: { w = "seven"; }
case 8: { w = "eight"; }
case 9: { w = "nine"; }
case 10: { w = "ten"; }
case 11: { w = "eleven"; }
default: { w = "twelve"; }
}
return w;
}
let rows = "";
for (i in range(1, 13)) {
rows = rows + str(i) + " " + name(i) + " " + str(-30 * i) + "\n";
}
plot.data("Data", rows);
plot.png("images/rotate_labels-2.png", 800, 600);
plot.cmd("reset");
plot.cmd("set angle degrees");
plot.cmd("unset key");
plot.cmd("set title 'variable color and orientation in plotstyle \"with labels\"' offset 0,-2");
plot.cmd("set xrange [0:13]");
plot.cmd("set yrange [0:13]");
plot.cmd("set xtics 1,1,12 nomirror");
plot.cmd("set ytics 1,1,12 nomirror");
plot.cmd("set border 3");
plot.cmd("plot $Data using 1:1:2:3:0 with labels rotate variable tc variable font ',20'");
plot.close();
end _lmcode_
r = run_lmcode(p);
assert(r.ok, json_stringify(r));
cp = system cp images/rotate_labels-2.png images/rotate_labels.png;
assert(cp.code == 0);
println("wrote images/rotate_labels.png (and images/rotate_labels-1.png .. images/rotate_labels-2.png)");