v1.2.2 — 2026-06-07
Scientific 2D/3D plotting using PLplot — a cross-platform plotting library that can render to PNG, PDF, SVG, X11, and Qt windows among other drivers.
(import (curry plplot))Linux (Debian / Ubuntu)
sudo apt install libplplot-devmacOS (Homebrew)
brew install plplotBuild with:
cmake -B build -DBUILD_MODULE_PLPLOT=ON
cmake --build build -j$(sysctl -n hw.logicalcpu) # macOS
cmake --build build -j$(nproc) # LinuxThe xwin driver requires X11/XQuartz, which is not installed by default on macOS. Use file-based or Qt drivers instead:
| Driver | Output | Notes |
|---|---|---|
"pngcairo" |
PNG file | Recommended for scripts |
"pdfcairo" |
PDF file | Good for print-quality output |
"svgcairo" |
SVG file | Scalable vector output |
"qtwidget" |
Interactive window | Requires brew install qt@6 and the qt6 module |
Example — render to PNG on macOS:
(pl-sdev "pngcairo")
(pl-sfnam "plot.png")
(pl-init)
...
(pl-end)Initialise PLplot. Call once before any drawing.
Close the current output device and finalise the plot.
Set the output driver before pl-init. Common drivers: "pngcairo", "pdfcairo", "svgcairo", "xwin", "qtwidget".
Set the output filename (used by file-based drivers like "pngcairo").
Advance to the next page (or sub-page). Pass 0 to advance to a fresh page.
Set up a standard viewport, axes, and labels in one call.
just: 0 = independent axes, 1 = equal scales, 2 = equal + square boxaxis: 0 = box only, 1 = box + axes, 2 = box + axes + numeric labels
Set the viewport in normalised device coordinates (0–1).
Set the world coordinate window.
Draw axes with tick marks. xopt/yopt are option strings (e.g. "bcnst" for a framed, labelled axis).
Set the x-axis label, y-axis label, and plot title.
Draw a line through the points given by lists xs and ys.
Draw points with symbol code code (integer). Negative codes draw lines between points.
Draw the string text at each point (x, y).
Select a colour from the default colour palette (0–15).
Set the line width in units of 0.005 mm (integer).
Set the line style: 1=solid, 2=dashed, 3=dotted, etc.
Draw a 3D mesh surface. xs and ys are 1D lists (axis tick values), zs is a 2D list of lists (ny rows × nx columns).
3D shaded surface with optional contour lines. opt is a bitmask; pass 0 for defaults. clev is a list of contour levels, nlev is the count.
Draw a 2D contour map. zs is a 2D list of lists (ny rows × nx columns). kx/lx and ky/ly are column/row index ranges (1-based). clev is a list of contour levels.
Draw a colour-shaded band.
Display a 2D array zs as a false-colour image.
Draw horizontal error bars at y = y1..y2 for each x.
Draw vertical error bars.
Draw text at world coordinate (x,y). dx/dy set the text direction, just sets horizontal justification (0=left, 0.5=centre, 1=right).
Fill the polygon defined by xs and ys with the current colour.
Set fill pattern. nlin=number of line families, inc and del are lists of inclinations and spacings.
Set character height and scale.
Set major tick mark size.
Set minor tick mark size.
Flush the output buffer (useful for interactive drivers).
(import (curry plplot))
(pl-sdev "pngcairo")
(pl-sfnam "output.png")
(pl-init)
(pl-adv 0)
(pl-env -3.14 3.14 -1.2 1.2 0 1)
(pl-lab "x" "sin(x)" "Sine wave")
(pl-col0 1)
(let* ((n 200)
(xs (map (lambda (i) (* (- i 100) (/ 3.14159 100.0))) (iota n)))
(ys (map sin xs)))
(pl-line xs ys))
(pl-end)(import (curry plplot))
(import (curry regex))
(pl-sdev "pdfcairo")
(pl-sfnam "phase.pdf")
(pl-init)
(pl-adv 0)
(pl-env -2.0 2.0 -2.0 2.0 0 1)
(pl-lab "x" "dx/dt" "Phase portrait")
; draw multiple trajectories
(for-each
(lambda (x0)
(let loop ((x x0) (v 0.0) (pts-x '()) (pts-y '()) (i 0))
(if (> i 500)
(begin
(pl-col0 (+ 1 (modulo (inexact->exact (floor (* x0 3))) 7)))
(pl-line (reverse pts-x) (reverse pts-y)))
(let ((ax (- (- x) (* 0.1 v))))
(loop (+ x (* 0.02 v))
(+ v (* 0.02 ax))
(cons x pts-x)
(cons v pts-y)
(+ i 1))))))
'(-1.8 -1.2 -0.6 0.0 0.6 1.2 1.8))
(pl-end)