Is it possible to let TikZ save and in subsequent compilation runs use the plot points generated with the PGF math library?

A (simple) example of such a function plotted that way is:

  \draw plot (\x,{sin(2*pi*\x r)});

Here, the PGF math library is used to calculate sin(2*pi*\x r). For complex expressions, this is quite time-intensive. I assume this time could be saved if the plot points were available as is the case when using a gnuplot ‘function’ plot. Then (if the plot is given an id) the plot points generated by gnuplot are saved to a .table file, so that they need not be regenerated unless the plot parameters have changed.

  • The big problem is that TeX doesn't really support arrays. A Tikz array is just a comma delimited text string. Dec 9, 2013 at 2:15
  • 3
    May be this answer helps you: tex.stackexchange.com/a/60370/1952. You can create a data file computed with pgfplotstable and use it afterwards to plot it.
    – Ignasi
    Dec 9, 2013 at 9:09

1 Answer 1


You can use \pgfplotstablenew command from pgfplotstable (which comes with pgfplots) to create a file with your plot points and some conditional to create it when you want. Next example creates the file when doesn't exist.

\usepackage{pgfplots, pgfplotstable}


    create on use/plot1/.style={
        create col/expr={sin (2*pi*\pgfplotstablerow)}

        line join=bevel,
        no markers,
        table/x expr={\coordindex},
        enlarge x limits=false,
   \addplot[red] table [y expr={\thisrow{plot1}}] {myplot.dat};



enter image description here

You must log in to answer this question.

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