The tikz terminal goes one step further than epslatex: instead of a PostScript graphic plus LaTeX text, gnuplot writes the entire figure — axes, curves and text — as a native TikZ picture in a single .tex file. LaTeX then draws the figure itself, so it blends completely into documents that already use TikZ.
set terminal tikz size 12.5cm,9cm
set output "spectrum.tex"
set title "Measured spectrum"
set xlabel "Frequency (Hz)"
set ylabel "Amplitude"
set grid
plot sin(x)*exp(-0.1*x) with lines linewidth 2 title "Damped sine"
set output
The output, spectrum.tex, contains a tikzpicture environment with the plot expressed as TikZ drawing commands. In your document you include it the same way as an epslatex fragment:
% in the preamble:
\usepackage{tikz}
% plus the style file gnuplot-lua-tikz.sty, which ships with
% gnuplot's Lua TikZ support and must be findable by LaTeX
% in the document:
\begin{figure}
\centering
\input{spectrum}
\caption{A damped sine wave.}
\end{figure}
The Lua requirement
Unlike the cairo and PostScript terminals, tikz is not a compiled-in C driver: it is implemented on top of gnuplot’s generic Lua terminal, driven by the script gnuplot-tikz.lua (you may also see it invoked in its explicit form, set terminal lua tikz). That has one practical consequence: the terminal only exists if your gnuplot was built with Lua support. If set terminal tikz answers with an unknown-terminal error, check the list printed by a bare set terminal command — if tikz is absent, your build lacks Lua, and you either install a Lua-enabled build (most full Linux distribution packages include it) or use epslatex / pdfcairo instead. The same Lua machinery generates the LaTeX style files (gnuplot-lua-tikz.sty and companions) that the document preamble relies on.
tikz or epslatex?
- Choose tikz when the document is already TikZ-based (Beamer presentations, TikZ diagrams next to the plots), when you want to hand-edit the generated drawing, restyle it with your document’s TikZ styles, or overlay TikZ annotations and arrows on top of the plot in LaTeX.
- Choose epslatex when you want the simpler, older and very battle-tested route, when compile time matters (a complex tikz figure — dense data, surfaces, images — can make LaTeX slow, because every segment becomes TeX drawing commands), or when your gnuplot build has no Lua support.
- Choose neither — plain pdfcairo plus
\includegraphics— when the paper does not need LaTeX-typeset figure text; it is the least moving parts of the three.
Common mistakes
- LaTeX cannot find gnuplot-lua-tikz.sty: the style file is not in your document folder or TeX search path. Copy it next to the document (it is distributed with gnuplot’s Lua TikZ files) or install it into your local texmf tree.
- pdflatex runs out of memory or takes minutes: the plot is too dense for TeX-drawn vector commands. Thin the data before plotting (for example with
everyon the plot command), simplify the figure, or switch that one figure to epslatex/pdfcairo. - Curves look slightly different from the screen version: TikZ renders line joins, dashes and marker shapes with its own conventions. Judge the figure from the compiled PDF, not from the interactive preview.
Related tutorials: The epslatex Terminal, The Gnuplot + LaTeX Workflow. See also the full Gnuplot Tutorials index.
Try it online: Draft the plot online first; the tikz export itself needs a local, Lua-enabled gnuplot. 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.
