From ConTeXt wiki
Jump to: navigation, search

< Modules | Graphics | Math >

Gnuplot is a portable command-line driven utility for function plotting for many platforms.

To make the examples on this page work, you need Gnuplot 4.6.0 or later (or self-compiled binary).


Minimal Example


% write a script for gnuplot
   plot sin(x)

% include the resulting graphic into the document

Calling gnuplot to create the graphic and postprocessing should happen automatically.


On most Linux installations this is probably already the case. On Windows gnuplot.exe is usually also shipped and you need to make sure that it is in PATH. In case that the binary has a different name, you could create a file gnuplot.bat with something like:
"C:\Program Files\gnuplot\bin\wgnupl32.exe" %*
(if that was the binary name) and put that file to a "visible place" (has to be found in PATH). Please note: if calling gnuplot from cmd works for you, there is no need to do anything extra.

To use the ConTeXt terminal (recommended)


You can fetch binaries from sourceforge (released versions) or from Tatsuro Matsuoka (latest cvs version).

Unix or Mac

The easiest way is to use version 4.6.0 or later shipped by your distribution. If that version is too old, you need to compile your own.

If you want to use the version from trunk:

# unofficial; you can also use official cvs
git clone git://
make install

I use ./configure --prefix=$PWD/inst to avoid cluttering the system and install gnuplot to my personal directory. You can use other flags to configure for a different choice of GUI terminals.

If you want to use the released version, get it from sourceforge and do the same, just skip the ./prepare.

The latest version of context terminal is available at

Feel free to contact Mojca in case of problems.

Creating stand-alone, whole-page plots

Here's an example of how to make a stand-alone ConTeXt document with one plot per page:

set term context standalone size 15cm,10cm header '\usetypescript[iwona]' font 'iwona,ss' 10dd
set output 'example.tex'
plot ...

More complex example


\setupGNUPLOT[terminal=tikz,option=color] % terminal=mp if you only have an old gnuplot at hand

% general settings for the whole document

   # you may use TeX commands to format the titles and axes
   set title '\bf Trigonometry'
   set xlabel '$x$'
   set ylabel '$y$'

   # to prevent uneven numbering: will result in
   # (0.0, 0.5, 1.0, 1.5, ...) instead of
   # (0, 0.5, 1, 1.5, ...)
   set format y '%.1f'

   plot tan(x) t '$\tan(x)$'

   plot 4*sin(x)+x t '$4\sin(x)+x$', x t '$x$' lt 3


Using other terminals

(Needs a revision.)

Gnuplot support output in different formats with, for example

set terminal mp color solid

will output a metapost document with colors and without dashed lines. After some appropriate preprocessing (with MPtoPDF for this particular case) this file can be included in PDF documents.

You can specify the terminal with

\setupGNUPLOT[terminal=mp,options=color solid]
set terminal mp color solid

But you have to be careful that you don't set any other terminal with output= then.

Currently supported terminals are (attention: links not from the latest documentation):

The current gnuplot-documentation can be downloaded here.


I (Mojca Miklavec) probably mentioned long time ago that I would like to have (or write?) support for Gnuplot inside ConTeXt, but I had no knowledge to do that. Peter M√ľnster posted the very first module for gnuplut support on the mailing list [1], but that version only worked with bash. In the days to follow Hans Hagen has written a new module (based on my numerous "possible and impossible" requests) and Taco additionally provided some bugfixes and minor changes.

The module provides an option to select the most appropriate/suitable driver according to the user's choice (metapost, png, pdf, postscript were the firs ones to be supported). Hans was wondering why there was no context terminal. I took over it's development, the code is almost finished by now, but I guess that Hans now regrets that question already.

He had to invest quite some time into fixing buggy inclusion of text into graphics using textext (if nothing else, he had to read and reply to all the mails [complaints] that me and Taco sent him), just to lead to the conclusion that textext was useless for graphics produced by Gnuplot: too slow and TeX ran out of memory after 10 minutes while processing approximately the 13th plot. After that the new marvellous \sometxt command was born.

I'm currently sticking tiny pieces together in the way I want the module to work. Hans could probably finish the same work that costs me a few days in a few minutes, but after dropping me a bone, he decided to leave me the joy of diving into ConTeXt internals and to let me figure out how to program in ConTeXt by myself. So I still keep spamming the mailing list with numerous questions and both Taco and Hans - without whom implementing the module would be impossible - keep answering.

Alternatives for Function Plotting

Other links

Slo Ministry of Higher Education Science and Technology.jpg


Personal tools
External Help