Menu

Gnuplot to LaTeX image

← TOC    ↑ Home    Gnuplot SVG TeX TeX PDF EPS SVG PNG JPEG

Gnuplot to LaTeX image

This page shows how to convert a Gnuplot file x.gp into a LaTeX figure you can include into a LaTeX document.

If you want to convert the Gnuplot file into a standalone *.tex file you can process using pdfLaTeX to create a standalone PDF file, see the [Gnuplot to LaTeX document] page instead.


Prepare Gnuplot file for the gxhconvert script

  • No terminal, no output file name
    Do not use
    set terminal ...
    set output ...
    
    in Gnuplot files you want to use with gxhconvert.
    Terminal type and output file name are provided by the gxhconvert script and passed as command line arguments to Gnuplot.
     
  • Optionally: Diagram width and height in special comments
    Special comments have two raute characters (`#') at the start of line, example:
    ##  width   =   10cm
    ##  height  =   10cm
    set xrange [0:10]
    plot x*x title "\\(y=x^2\\)"
    
    The gxhconvert script uses the tikz terminal instead of the usual cairolatex pdf terminal if width and height are specified. Make sure you have installed the "gnuplot-lua-tikz" package for LaTeX.
     
  • Optionally: Terminal type and setup in special comments
    Example:
    ##  terminal    =   tikz
    ##  terminal setup  =   solid
    
    For the terminal you can choose either "tikz" or "cairolatex".
     
  • Two backslashes in Gnuplot file for each LaTeX backslash
    Gnuplot uses the backslash to escape some characters. So for each backslash you want to pass to LaTeX, write a sequence of two backslashes in the Gnuplot file.
    Example:
    set xlabel "\\(\\frac{x}{x_0}\\rightarrow\\)"
    set ylabel "\\(\\overset{\\uparrow\\vspace{0.3em}}{y}\\)" rotate by 0
    
    Note: The \overset instruction requires a line
    preamble line = \usepackage{amsmath}
    
    in the gxhconvert.conf file in the current working directory.

Choice 1: Use gxhconvert

Procedure

gxhconvert -o=tex x.gp

Options

Option Purpose
--pgf Use the Gnuplot tikz terminal to write PGF instructions into the *.tex output file instead of including a supplemental *-inc.pdf file.
--eps Create EPS+TeX file pair instead of a PDF+TeX file. The options --pgf and --eps are mutually exclusive.

Choice 2: Manual conversion, use PDF+TeX combination

Procedure

gnuplot -e "set terminal cairolatex pdf input ; set output 'x.tex'" x.gp

Choice 3: Manual conversion, use EPS+TeX combination

Procedure

gnuplot -e "set terminal cairolatex eps input ; set output 'x.tex'" x.gp

Choice 4: Manual conversion, use PGF instructions

Procedure

gnuplot -e "set terminal tikz nostandalone plotsize 10cm,7cm ; set output 'x.tex'" x.gp
← TOC    ↑ Home    Gnuplot TeX TeX PDF EPS SVG PNG JPEG

Related

Wiki: Gnuplot to LaTeX document

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.