18 Apr 2026

GNU plot preamble

A practical tutorial for using gnuplot_preamble in Maxima to produce clean, publication-style plots.

maxima gnuplot

Maxima can pass raw gnuplot directives to the plotting backend through gnuplot_preamble, enabling fine control over plot aesthetics. This approach is especially useful for scientific figures where borders, ticks, grids, labels, legends, numeric formatting, and sampling density must be standardized.

What gnuplot_preamble Does

The option gnuplot_preamble injects a single string of gnuplot commands into the generated plotting script. The content of this string must be valid gnuplot syntax (not Maxima syntax). Typical uses include:

Basic Structure and Minimal Example

The general pattern is to include [gnuplot_preamble, β€œβ€¦β€] among the plotting options, writing all gnuplot commands inside one string and separating them with semicolons.

plot2d(
    expr,
    [x, xmin, xmax],
    [plot_format, gnuplot],
    [gnuplot_preamble,
     "gnuplot command 1;
      gnuplot command 2;
      gnuplot command 3;"]
);

A minimal working example with a smooth curve and clean framing is:

k1 : 1.0$
k2 : 0.5$
w  : 1.0$

y : exp(w*t)*(k2*t + k1)$

plot2d(
    y,
    [t, -2, 2],
    [plot_format, gnuplot],
    [xlabel, "t"],
    [ylabel, "y(t)"],
    [legend, "y(t)=exp(w*t)*(k2*t+k1)"],
    [gnuplot_preamble,
     "set border 31 lw 2;
      set tics out nomirror scale 1.2;
      set grid;
      set samples 1000;"]
);

Meaning of Common gnuplot Directives

The commands below are commonly used to achieve a β€œpremium” scientific look; they are written exactly as gnuplot expects.

Premium Scientific Example and Reusable Template

The following example combines the most useful directives into one consistent style while avoiding terminal-specific commands.

k1 : 1.0$
k2 : 0.5$
w  : 1.0$

y : exp(w*t)*(k2*t + k1)$

plot2d(
    y,
    [t, -2, 2],
    [plot_format, gnuplot],
    [xlabel, "Time, t"],
    [ylabel, "y(t)"],
    [legend, "y(t)=exp(w*t)*(k2*t+k1)"],
    [style, [lines, 4]],
    [gnuplot_preamble,
     "set border 31 lw 2.2;
      set tics out nomirror scale 1.3;
      set mxtics 2;
      set mytics 2;
      set xtics font 'Times New Roman,20';
      set ytics font 'Times New Roman,20';
      set xlabel 'Time, t' font ',18';
      set ylabel 'y(t)' font ',18';
      set key top left box opaque font ',14';
      set grid xtics ytics mxtics mytics back lw 1;
      set zeroaxis lw 1.2;
      set samples 1500;
      set format x '%.1f';
      set format y '%.2f';
      set lmargin 10;
      set rmargin 4;
      set tmargin 3;
      set bmargin 4;"]
);

Share This Page