A gnuplot figure is annotated with four settings: set title for the heading, set xlabel and set ylabel for the axes, and set key for the legend. The script below shows all four, including font sizes, on a small data plot.
The example plots a file sales.dat with month numbers in column 1 and revenue in column 2:
1 12400
2 13150
3 12800
4 14900
5 15750
6 16200
set title "Monthly Sales" font ",16"
set xlabel "Month" font ",13"
set ylabel "Revenue (USD)" font ",13"
set tics font ",11"
set key top left box font ",11"
plot "sales.dat" using 1:2 with linespoints linewidth 2 pointtype 7 title "2026 sales"
What each part does
Each annotation is set before the plot command. set title "Monthly Sales" font ",16" sets the heading and its size. The font spec ",16" leaves the font family empty (so the terminal default is used) and sets only the size — write font "Sans,16" if you also want a specific family. The same pattern works for set xlabel and set ylabel: text first, then an optional font clause. Axis labels should always name the quantity and, where it matters, the unit — “Revenue (USD)” here.
set tics font ",11" shrinks the numbers along both axes so they do not compete with the labels. The legend is controlled by set key: top left places it inside the plot at the upper left, box draws a frame around it, and font ",11" sizes its text. The text shown in the key comes from the title "..." clause of each plot element — here “2026 sales”. Use notitle on a plot element to keep it out of the key, and unset key to remove the legend entirely.
Variants and going further
Free-floating text uses set label: set label "peak" at 6, 16200 offset 1,1 places the word “peak” next to a data coordinate, and labels are numbered so you can clear one with unset label 1. For a key outside the plotting area, try set key outside right or set key below. Two-line titles are legal — embed a newline with set title "Monthly Sales\nFirst Half 2026" in a script file where the terminal supports the enhanced text mode, which most file terminals (pngcairo, pdfcairo) enable by default.
Common mistakes
- Legend covers the data: the default key sits at the top right. Move it with
set key top left(orbottom right,outside), or make room by extending the axis range. - Font size ignored: you set a size but the terminal was never told to use enhanced text or the font name is misspelled. Stick to the
font ",14"size-only form while testing, and confirm the plot again — size-only specs work on every terminal.
Related tutorials: Your First Gnuplot Plot, Line Styles, Colors and Point Types. See also the full Gnuplot Tutorials index.
Try it online: Titles, labels and key placement update instantly in the online terminal, which makes it a fast way to fine-tune placement. 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.
