Fonts in Gnuplot: Choosing, Sizing and Finding Them

On the cairo terminals (pngcairo, pdfcairo, epscairo) and the svg terminal, a gnuplot font is a single string of the form "Family,Size" — for example font "Arial,12". You set it once on the terminal line as the default for the whole figure, and override it per element (title, labels, tics, key) wherever one piece of text needs to differ.

set terminal pngcairo size 1000,700 enhanced font "Arial,12"
set output "report.png"
set title "Quarterly Report" font "Arial,16"
set xlabel "Month" font "Arial,13"
set ylabel "Revenue" font "Arial,13"
set tics font "Arial,10"
set key font "Arial,10"
plot "revenue.dat" using 1:2 with linespoints linewidth 2 title "Revenue"
set output

Read the font strings from left to right: family first, then a comma, then the size in points. Either half can be omitted — font "Arial" changes only the family and keeps the current size, font ",14" changes only the size and keeps the family (that size-only form is the quick fix when a figure’s text is uniformly too small). The terminal-line font is the default; the per-element font clauses on set title, set xlabel, set tics and set key override it locally, which is the pattern the script above uses: big title, medium labels, small tics and key.

Which fonts can you actually use?

Gnuplot does not ship its own font library for these terminals — drawing is done by Cairo and text layout by Pango, which ask the operating system’s font machinery for the family you named. The gnuplot documentation says the same thing in its own words: under Windows the fonts live in the Fonts entry of the system settings, and under Unix they are handled by fontconfig. So “which fonts does gnuplot have?” is really “which fonts does this computer have?”, and you check it with the system’s own tools:

  • Linux (and other fontconfig systems): run fc-list in a shell to list every installed family (add : family — fc-list : family | sort -u — for a clean unique list of names you can paste into a script).
  • Windows: open Settings → Personalisation → Fonts (or the Fonts folder in Control Panel) and use the family names exactly as shown there, for example Arial, Times New Roman, Consolas.
  • macOS: open the Font Book app to browse installed families; Macs that also have fontconfig installed (for example via a gnuplot package manager build) can use fc-list in a terminal as well.

The generic families Sans, Serif and Monospace always resolve to some real font on every system, which is why so many examples use font "Sans,12": the script stays portable even though the exact typeface differs between machines.

When a font is missing: silent fallback

If the named family is not installed, gnuplot does not stop with an error — Pango/fontconfig quietly substitute the closest available font and the plot renders anyway. That is convenient and dangerous in equal measure: convenient because scripts never crash over a font, dangerous because the figure you exported on a colleague’s machine can have subtly different text widths, so labels may collide or a carefully sized title may overflow. The defences are simple: prefer families you have verified with the tools above, prefer the generic families in scripts meant to be shared, and always judge the final figure from the exported file, not from an interactive window on a different machine. A related trap: requesting a style the family does not have (an italic or bold variant that does not exist) is likewise synthesized or substituted, so check bold/italic labels in the export too.

Common mistakes

  • Font clause has no effect: it was placed after the plot command, or set on the interactive terminal and the export re-set the terminal without a font. Terminal options belong on the set terminal line, before plotting.
  • Text scales oddly in PDF output: pdfcairo applies a default fontscale 0.5, so a nominal 12-point font appears smaller in the finished PDF than in a PNG of the same script. If PDF text looks small, raise the sizes or set fontscale 1.0 on the pdfcairo line — this surprises almost everyone once.

Related tutorials: Titles, Labels and the Key, PNG vs PDF in Gnuplot. See also the full Gnuplot Tutorials index.

Try it online: Try the per-element font clauses in the online terminal to see the size hierarchy before exporting. 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.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *