gnuplot gallery · examples/lines_arrows.lms

Lines, points and arrows

line, point and arrow styles (gnuplot lines_arrows.dem)

Loading the WebAssembly host…

What runs

The page fetches examples/lines_arrows.bin, 5,107 bytes of lmcode bytecode (sha256 1999c88427d0…), 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.

# Line types, dash patterns, point intervals and arrow styles: gnuplot "lines_arrows.dem".
# Image 1: line colour and dash type chosen independently (linetype vs linecolor).
# Image 2: 'pointinterval' with a UTF-8 character as the point symbol.
# Image 3: arrow styles (heads, filled/empty/nofilled), compared with 'with vectors'.
mkdir("images");
mkdir("build");
if (!file_exists("examples/data/arrowstyle.dat")) {
  mkdir("examples/data");
  write_file("examples/data/arrowstyle.dat", http_get("https://raw.githubusercontent.com/lmctl-ai/lmplot/main/examples/data/arrowstyle.dat"));
}
p = _lmcode_ cli="lmplot" install="github:lmctl-ai/lmplot@v0.3.1";

# --- 1: independent colours and dash styles ---
plot.png("images/lines_arrows-1.png", 800, 600);
plot.cmd("set termoption dash");
plot.cmd("set xrange [-0.5:3.5]");
plot.cmd("set yrange [-1:1.4]");
plot.cmd("set bmargin 7");
plot.cmd("unset ytics");
plot.cmd("unset xtics");
plot.cmd("set title 'Independent colors and dot/dash styles'");
plot.cmd("set xlabel 'You will only see dashed lines if your current terminal setting permits it'");
plot.cmd("unset colorbox");
# reset the base linetypes 1..5 to the terminal's five dash patterns
plot.cmd("set for [i=1:5] linetype i dt i");
plot.cmd("set style line 1 lt 2 lc rgb 'red' lw 3");
plot.cmd("set style line 2 lt 2 lc rgb 'orange' lw 2");
plot.cmd("set style line 3 lt 2 lc rgb 'yellow' lw 3");
plot.cmd("set style line 4 lt 2 lc rgb 'green' lw 2");
plot.cmd("set label 1 'set style line 1 lt 2 lc rgb \"red\" lw 3' at -0.4, -0.25 tc rgb 'red'");
plot.cmd("set label 2 'set style line 2 lt 2 lc rgb \"orange\" lw 2' at -0.4, -0.35 tc rgb 'orange'");
plot.cmd("set label 3 'set style line 3 lt 2 lc rgb \"yellow\" lw 3' at -0.4, -0.45 tc rgb 'yellow'");
plot.cmd("set label 4 'set style line 4 lt 2 lc rgb \"green\" lw 2' at -0.4, -0.55 tc rgb 'green'");
plot.cmd("set label 5 'plot ... lt 1 lc 3 ' at -0.4, -0.65 tc lt 3");
plot.cmd("set label 6 'plot ... lt 3 lc 3 ' at -0.4, -0.75 tc lt 3");
plot.cmd("set label 7 'plot ... lt 5 lc 3 ' at -0.4, -0.85 tc lt 3");
plot.cmd("plot cos(x) ls 1 title 'ls 1', cos(x-.2) ls 2 title 'ls 2', cos(x-.4) ls 3 title 'ls 3', cos(x-.6) ls 4 title 'ls 4', cos(x-.8) lt 1 lc 3 title 'lt 1 lc 3', cos(x-1.) lt 3 lc 3 title 'lt 3 lc 3', cos(x-1.2) lt 5 lc 3 title 'lt 5 lc 3'");
plot.close();

# --- 2: point interval with unicode glyphs as point symbols ---
plot.png("images/lines_arrows-2.png", 800, 600);
plot.cmd("unset for [i=1:8] label i");
plot.cmd("set encoding utf8");
plot.cmd("set title 'The pointinterval property also works with character point symbols'");
plot.cmd("set bmargin 6");
plot.cmd("set offset .05, .05");
plot.cmd("set xrange [-0.5:3.3]");
plot.cmd("set style data linespoints");
plot.cmd("set pointintervalbox 1.5");
plot.cmd("unset xlabel");
plot.cmd("plot '+' using 1:(cos(x-1.)) with line lt -1 lw 1 title 'lw 1', '+' using 1:(cos(x)) lt -1 pi -4 pt 'C' title 'pi -4', '+' using 1:(cos(x-.8)) lt -1 pi -3 pt 'D' title 'pi -3 pt \"D\"', '+' using 1:(cos(x-.2)) lt -1 pi -6 pt '✠' tc rgb 'blue' title 'pi -6 tc rgb \"blue\"', '+' using 1:(cos(x-.4)) lt -1 pi -3 pt '✲' title 'pi -3', '+' using 1:(cos(x-.6)) lt nodraw pi 5 pt '☺' title 'lt nodraw pi 5', '+' using 1:(cos(x+.2)) with line lt -1 lw 2 title 'lw 2'");
plot.close();

# --- 3: arrow styles ---
plot.png("images/lines_arrows-3.png", 800, 600);
plot.cmd("reset");
plot.cmd("set xrange [-1000:1000]");
plot.cmd("set yrange [-178:86]");
plot.cmd("set tics scale 0");
plot.cmd("set style line 1 lt 1 lw 2");
plot.cmd("set style line 2 lt 1 lc rgb 'skyblue' lw 2");
plot.cmd("set style arrow 1 head filled size screen 0.025,30,45 ls 1");
plot.cmd("set style arrow 2 head nofilled size screen 0.03,15 ls 2");
plot.cmd("set style arrow 3 head filled size screen 0.03,15,45 ls 1");
plot.cmd("set style arrow 4 head filled size screen 0.03,15 ls 2");
plot.cmd("set style arrow 5 heads filled size screen 0.03,15,135 ls 1");
plot.cmd("set style arrow 6 head empty size screen 0.03,15,135 ls 2");
plot.cmd("set style arrow 7 nohead ls 1");
plot.cmd("set style arrow 8 heads size screen 0.008,90 ls 2");
# eight explicit arrows with matching labels, generated by a gnuplot do-loop
plot.script("do for [i=1:8] { y = -90-10*i; set arrow i from -500,y rto 1000,0 as i; set label i sprintf('arrowstyle %d:', i) at -520,y right }");
plot.cmd("set title 'Top: plot with vectors arrowstyle 1, Bottom: explicit arrows'");
plot.cmd("plot 'examples/data/arrowstyle.dat' using 1:2:(0):3 notitle with vectors arrowstyle 3");
plot.close();
end _lmcode_
r = run_lmcode(p);
assert(r.ok, json_stringify(r));
cp = system cp images/lines_arrows-1.png images/lines_arrows.png;
assert(cp.code == 0);
println("wrote images/lines_arrows.png (and images/lines_arrows-1.png .. images/lines_arrows-3.png)");