Fix Garbled UTF-8 Text in Gnuplot Labels and Titles

Your data is fine and the curve is right, but the text is wrong: Température loses its accent, the degree sign in 25 °C turns into two strange characters, or a Greek letter in the axis label is replaced by a blank or a box. These are encoding and font problems, and they are fixable.

What is going on

Three separate links have to agree before a character renders correctly. Gnuplot must interpret the bytes in your script using the right encoding; the terminal must pass those characters through; and the font used for the label must actually contain the glyph. A failure at any one link garbles the output, and each failure looks slightly different — mojibake (accented characters exploding into two characters) usually means an interpretation mismatch, while empty boxes usually mean a missing glyph in the font.

Causes, most likely first

  1. Gnuplot is not set to UTF-8. Without it, gnuplot may fall back to a legacy default encoding (historically latin1 in many builds) and misread UTF-8 bytes.
  2. The terminal’s font has no glyph for your characters. The encoding can be perfect and the output still shows boxes if the chosen font simply does not contain, say, Greek letters or the degree sign.
  3. The script file itself is not UTF-8. An editor saved it in a legacy code page, so the bytes on disk are not what any UTF-8 setting expects.

Fixes, step by step

1. Tell gnuplot the input is UTF-8

Put this near the top of the script, before any labels are defined:

set encoding utf8

Run show encoding in a session to see the current setting before you change it — if it already says utf8, your problem is at link two or three, not here.

2. Switch to a font that has the glyphs

The cairo terminals (pngcairo, pdfcairo) and the svg terminal use system fonts, so pick a font with broad coverage and ask for it explicitly:

set terminal pngcairo size 1000,700 font "DejaVu Sans,12"
set encoding utf8
set title "Température (°C)"
set xlabel "α angle"

DejaVu Sans ships on most Linux systems and covers a wide range of symbols; the same approach works with any installed font that has the characters you need. Our guide to gnuplot fonts shows how to list the fonts available on Windows, macOS and Linux and how font selection differs per terminal.

3. Verify the file itself is UTF-8

On Linux/macOS, file script.gp reports the file’s encoding; look for “UTF-8”. In an editor, check the save encoding (most editors show it in the status bar) and re-save as UTF-8 if it says ANSI or a legacy code page. A script typed on one machine and plotted on another is the classic way this bites: the bytes travelled, the encoding assumption did not.

4. For interactive terminals, prefer enhanced text as a fallback

For a handful of common symbols, the enhanced mode of most terminals offers escapes such as {/Symbol a} for alpha or \260-style octal escapes in postscript — useful when you cannot change the font, though UTF-8 plus a proper font is the cleaner fix for real text in your own language.

A minimal script that works

reset
set encoding utf8
set terminal pngcairo size 900,600 font "DejaVu Sans,12"
set output "utf8-demo.png"
set title "Température en °C — café"
set xlabel "temps (s)"
set ylabel "θ (°C)"
plot 20 + 5*sin(x/2) with lines title "mesure α"
set output

If this file — saved as UTF-8 — renders every accent and symbol correctly, your setup is fine and the fault is in the encoding of your original script file: re-save it as UTF-8 and keep set encoding utf8 as the first line. If some characters still show as boxes, it is the font: change the font argument and re-run.

Still stuck?

The official documentation at gnuplot.info includes the full command reference, and the gnuplot-info mailing list linked there is the best place to ask when a script misbehaves in a way this page does not cover — include the exact error message and a small sample of your data when you post.

Related troubleshooting

Similar Posts

Leave a Reply

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