Menu

Gnuplot to PNG

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

Gnuplot to PNG

This page shows how to convert a Gnuplot file named x.gp into a PNG image.

When converting vector graphics (like Gnuplot) to bitmap images (like PNG) you have to specify a resolution. This is the number of pixels per inch.


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=png -r=_resolution_ x.gp

See the [gxhconvert manual] for a full description of the gxhconvert script.

Options

Option Purpose
-a
--alpha
Create alpha channel. Untouched input regions result in transparent output regions.
--pgf Use PGF instructions in the intermediate *.tex file instead of including a *.pdf file.
--interlaced Create interlaced PNG. The start of the file (data stream) allows to render the image in low quality, details for better quality follow.
--optimized Optimize (decrease) file size. Computation takes a little longer and uses more memory.
--ultra-optimized PNG file size optimization, do exhaustive search with large number of trials using optipng options
"-zc8-9 -zm1-9 -zs0-3 -f0-5"
--web Shortcut for
"--interlaced --optimized --ultra-optimized".

Choice 2: Manual conversion, create alpha channel, use PDF support file

Procedure

gnuplot -e "set terminal cairolatex pdf standalone ; set output 'x.tex'" x.gp
pdflatex -interaction=nonstopmode x
pdf2svg x.pdf x.svg
inkscape --batch-process --export-type=png --export-overwrite --export-filename=x.png --export-dpi=_resolution_ --export-area-page x.svg

Temporary files

  • x.tex
  • x-inc.pdf
  • x.log
  • x.aux
  • x.pdf
  • x.svg

Choice 3: Manual conversion, create alpha channel, use PGF instructions

Procedure

gnuplot -e "set terminal tikz standalone plotsize 10cm,7cm ; set output 'x.tex'" x.gp
pdflatex -interaction=nonstopmode x
pdf2svg x.pdf x.svg
inkscape --batch-process --export-type=png --export-overwrite --export-filename=x.png --export-dpi=_resolution_ --export-area-page x.svg

Temporary files

  • x.tex
  • x.log
  • x.aux
  • x.pdf
  • x.svg

Choice 4: Manual conversion, no alpha channel, use PDF support file

Procedure

gnuplot -e "set terminal cairolatex pdf standalone ; set output 'x.tex'" x.gp
pdflatex -interaction=nonstopmode x
pdftoppm -r _resolution_ x.pdf | pnmtopng > x.png

Temporary files

  • x.tex
  • x-inc.pdf
  • x.log
  • x.aux
  • x.pdf

Choice 5: Manual conversion, no alpha channel, use PGF instructions

Procedure

gnuplot -e "set terminal tikz standalone plotsize 10cm,7cm ; set output 'x.tex'" x.gp
pdflatex -interaction=nonstopmode x
pdftoppm -r _resolution_ x.pdf | pnmtopng > x.png

Temporary files

  • x.tex
  • x.log
  • x.aux
  • x.pdf
← TOC    ↑ Home    Gnuplot TeX TeX PDF EPS SVG PNG JPEG

Related

Wiki: gxhconvert manual

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.