The complete workflow has four stages: a gnuplot script produces the figure, a LaTeX-aware terminal (epslatex or tikz) produces the includable file, the document pulls it in with \input or \includegraphics, and one compile produces the paper. This page walks the whole chain once, with the exact commands at each step.
Step 1 — One script per figure
Keep each figure as its own small script that sets its terminal, its output and its plot, in that order. A script per figure (rather than one giant script) means a reviewer comment about Figure 3 costs you one file edit and one command, and the scripts double as the figure’s provenance.
# fig-decay.gp
set terminal epslatex size 12.5cm,9cm color colortext
set output "fig-decay.tex"
set xlabel "$t$ (s)"
set ylabel "$N(t)$"
set xrange [0:10]
plot exp(-0.5*x) with lines linewidth 2 title "$e^{-t/2}$"
set output
Step 2 — Run gnuplot, get the figure files
gnuplot fig-decay.gp
# produces: fig-decay.tex + fig-decay.eps
With the epslatex terminal you get the familiar pair: the .tex fragment and the .eps drawing. If you chose the tikz terminal instead, the same command produces a single .tex file containing a TikZ picture (and your preamble then needs the tikz package and the gnuplot-lua-tikz style file). If you chose pdfcairo, you get a single .pdf figure file — pick exactly one of the three routes per paper and stay consistent.
Step 3 — Include the figure
% preamble for the epslatex route:
\usepackage{graphicx}
\usepackage{color}
\begin{figure}
\centering
\input{fig-decay}
\caption{Decay curve, generated by gnuplot.}
\label{fig:decay}
\end{figure}
% for the pdfcairo route, the same figure is one line instead:
% \includegraphics{fig-decay.pdf}
The rule of thumb: LaTeX-typeset terminals (epslatex, tikz) are included with \input because the file is LaTeX code; finished graphics files (PDF from pdfcairo, or a converted EPS) are included with \includegraphics because the file is a graphic. Compile with your usual engine — for epslatex under pdflatex, remember the EPS needs the epstopdf conversion that modern distributions perform automatically, or convert it once yourself. A Makefile or a three-line shell script that runs gnuplot on every .gp file before calling pdflatex makes the whole build one command, and guarantees no stale figure ever survives into a submission.
Step 4 — The same workflow in Overleaf
Nothing about this chain is tied to a local install: in an Overleaf project you can upload the generated .tex fragment (and its .eps companion, converted to PDF if your project compiles with pdflatex, or use the tikz .tex alone) alongside your .gp script for reference, and \input it exactly as above — the fragment is ordinary LaTeX, so Overleaf typesets it like any other part of the document. Keeping the .gp script in the project (even though Overleaf does not run gnuplot) means the figure’s source travels with the paper and any co-author can regenerate the fragment locally in seconds.
Common mistakes
- Editing the generated .tex by hand: the next gnuplot run overwrites it. All changes belong in the .gp script — treat generated files as build output.
- Mixing routes in one paper: some figures via epslatex, some via PNG screenshots of the interactive window, gives mismatched fonts and line weights that reviewers notice. One route, one template, every figure.
- Forgetting to rebuild before submitting: data changed, figure didn’t. The one-command build (gnuplot for all scripts, then pdflatex) exists precisely to make this mistake impossible.
Related tutorials: The epslatex Terminal, The TikZ Terminal. See also the full Gnuplot Tutorials index.
Try it online: Prototype each figure in the online terminal, then save it as a .gp file in your paper project and run the workflow locally. 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.
Keep the sources safe: A finished figure is easy to re-export, but only if you still have the .gp script, the data file and the generated .tex fragment that produced it. Back those source files up with your paper: pCloud is one option for keeping them synced and versioned off your laptop. Affiliate link: see our Affiliate Disclosure.
