One figure with several panels is a gnuplot multiplot: set multiplot layout reserves a grid, each following plot fills the next cell, and unset multiplot closes the figure. The script below builds a 2×2 panel of four related curves.
set multiplot layout 2,2 rowsfirst title "Four Views of Related Functions" font ",14"
set title "sin(x)"
plot sin(x) with lines linewidth 2 notitle
set title "cos(x)"
plot cos(x) with lines linewidth 2 notitle
set title "sin(x) * cos(x)"
plot sin(x) * cos(x) with lines linewidth 2 notitle
set title "exp(-x*x)"
set xrange [-3:3]
plot exp(-x*x) with lines linewidth 2 notitle
unset multiplot
What each part does
set multiplot layout 2,2 starts multiplot mode with 2 rows and 2 columns; rowsfirst fills cells left-to-right across the first row before moving down (the alternative, columnsfirst, fills down the first column). The title "..." on the same line is the whole-figure title, drawn above the grid. From that point, every plot command draws into the next cell using whatever settings are active — that is why each panel sets its own set title first, and why the last panel can narrow its xrange without affecting the others.
Settings are sticky across panels: a range, label or style set before panel 1 stays in force until changed. Use that deliberately — set shared elements (font, grid, y range) before the first panel so all four align, then override only what differs per panel. unset multiplot ends the figure and, for file terminals, completes the image file; forgetting it leaves the output unfinished.
Variants and going further
For panels that must share an axis exactly — the standard trick for comparable measurements — set the same xrange/yrange before the multiplot and add set lmargin at screen 0.12-style fixed margins (or simply identical margins via set margins in newer scripts) so the plot boxes line up even when y labels differ in width. Manual placement without a grid is also possible: omit layout, then position each panel with set origin and set size before its plot. In gnuplot 6.0.5, interactive multiplots gained full mouse support including pan and zoom with replot, which makes exploring panelled figures in the qt terminal noticeably smoother.
Common mistakes
- All panels show the same title or range: sticky settings were set inside the loop of panels but never changed per panel. Set per-panel titles and ranges immediately before each
plot, not once at the top. - Output file is empty or cut off: the script ended while still in multiplot mode. Always finish with
unset multiplot— for file terminals the figure is only finalised at that point.
Related tutorials: 3D Plots with splot, Your First Gnuplot Plot. See also the full Gnuplot Tutorials index.
Try it online: Multiplots render in the online terminal as a single figure, so layout experiments are easy to check there. Paste the script into the Gnuplot Online terminal and run it in your browser — no install needed. To run gnuplot locally instead, see the installation guide and the download page.
Go deeper: For a systematic walk through gnuplot from first plots to publication-ready figures, see Gnuplot in Action by Philipp K. Janert — Janert is a gnuplot developer, and the book is the most complete tutorial reference for the program. Affiliate link: see our Affiliate Disclosure.
