I do not know if what I am bringing up is a feature or a bug.

I am trying to get a cos x trig plot in degrees generated by gnuplot and plotted by TikZ. My .gnuplot file looks like this:

set table "trig.cosinex.table"; set format "%.5f"
set angles degrees; set samples 500; plot [x=0:360] cos(x)

When I compile my .tex file with Tikz/lualatex, the .gnuplot file becomes

set table "trig.cosinex.table"; set format "%.5f"
set samples 500; plot [x=0:360] cos(x)

The set angles degrees; part is deleted.

The gnuplot-relevant line in my .tex file is:

\draw [domain=0:360, samples=500, smooth] plot[id=cosinex] function {cos(x)}; % anm I missing a prefix here?

Kindly note that:

a. I hand generate the .table file from the .gnuplot file by running it through gnuplot.

b. TikZ/lualatex does not generate a .table file even if it does not exist (contrary to manual?) but only overwrites the .gnuplot file.

My questions are:

  1. How can I get TikZ to specify the angles to be degrees in the .gnuplot file that it overwrites? [If overwriting cannot be prevented.]
  2. How to prevent TikZ from overwriting my .gnuplot file in the first place? [After hand-compilation with gnuplot, the .table is left untouched by TikZ during multiple compilations as specified but the .gnuplot file is altered as above. So, repeat hand-compilation produces a wrong .table file and does not give correct results.]


  • Regarding (b), are you running tex with shell escapes enabled? Otherwise, it isn't allowed to call gnuplot and it just generates the .gnuplot file for you to use to generate the .table data. Apr 30, 2012 at 13:10
  • I am using the vanilla flavoured lualatex and xelatex from TeXLive 2011. The log files show 'restricted \write18 enabled` for both formats. I believe that this is sufficient but would appreciate confirmation.
    – chandra
    Apr 30, 2012 at 13:25
  • No, that's not sufficient. The restricted\write18 is allowed to execute a limited number of prespecified programs, of which gnuplot is not one. You need to run xelatex -shell-escape (lualatex might have a different option for this). Apr 30, 2012 at 13:37
  • Thanks. --enable-write18 seems to work with both xelatex and lualatex on my system.
    – chandra
    Apr 30, 2012 at 14:08

1 Answer 1


When you use \draw ... plot ... function {<plot command>}, the first thing TikZ does is generate the .gnuplot file with the default options and the <plot command>. Then it tries to execute gnuplot with the .gnuplot file. This is a feature (it's what function is supposed to do), and works as described in the manual.

If all you want to do is plot the .plot file generated by calling gnuplot manually, then you shouldn't use the function command, but simply file. In your case, you could use

\draw [smooth] plot file {texse.cosinex.table};

Note that the domain, samples and id keys have no effect when plotting data from a file.

If you want to use the function command (i.e. you want to generate the .gnuplot file from within TikZ) with degrees, you can use raw gnuplot to provide the appropriate options:

\draw [smooth] plot[id=cosinex, raw gnuplot] function {set samples 500; set angles degrees; plot [0:360] cos(x)};

Or you could change the .gnuplot skeleton using

  \xdef\pgf@gnuplot@head{set table \noexpand\pgf@plottablefile@quoted; set angles degrees; set format "%.5f"}

in your preamble. Then you can plot your function as desired:

\draw [domain=0:360, samples=500, smooth] plot[id=cosinex] function {cos(x)};
  • Thank you. For invoking gnuplot, I needed to add --enable-write18; the default is not sufficient. I have tested out both solutions and they work. Only I am unsure why you have x=0.2 in \draw [smooth,x=0.2] plot file {texse.cosinex.table};. Removing it gave me what I wanted. Parts of your answer would help being put into the pgfmanual.
    – chandra
    Apr 30, 2012 at 14:00
  • @chandra: Ah, sorry, the x=0.2 was necessary in my example document because otherwise the plot would have been much too wide.
    – Jake
    Apr 30, 2012 at 14:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .