I often come to a point, where I want a plot of a set of data or just a simple function to be included into my TeX file. The usual naive approach would be to save the plot as a vector or pixel graphic and just import it with the graphicx package.

But this has a downside. Axeslabels for example are often over or undersized.

So another option I tried is gnuplot and the terminal option epslatex. Although this fixes the problem with the axeslabel writing both a vector graphic file and a tex file I found this method to be very impractical when I wanted to change (a small mistake e.g.) in the axeslabel.

So I wanted to know what is the most practical way of creating and including a plot in a LaTeX file making it compatible with size and font of the pdfLaTeX output?

EDIT: The emphasis lies on plotting data points from a file (not plotting an analytic function, thats just to show some limiting behavior).

  • Another user asked a very similar question today tex.stackexchange.com/q/257833/3235
    – percusse
    Jul 30, 2015 at 8:38
  • Thx...I am more interested in plotting data sets. I only plot functions when I want to show some assymptotic behavior. Is Tikz really suited to plot data points from file? Jul 30, 2015 at 8:46
  • Take a look at pgfplots and pgfplotstable
    – Ignasi
    Jul 30, 2015 at 8:50
  • Can you put a small dataset? It is not possible to estimate what your points look like.
    – percusse
    Jul 30, 2015 at 8:52
  • Doing this with R and integrate in your .tex document with Sweave is perfect for the job. Another option would be gnuplot using the epslatex terminal.
    – vaettchen
    Jul 30, 2015 at 8:59

1 Answer 1


If you want to use gnuplot instead of pgf bundles for some reason, I would suggest you use tikz terminal option. Here is the procedure.

First, we must make a .tex file which draws a graph you want. Let me plot a sine curve in this demo because I do not have the plotting data. However, you can also do everything you can with gnuplot, including plot "foo.csv". In gnuplot, run the following:

set terminal tikz
set output "graph.tex"
set xlabel "set $x$ axis label as you like"
set ylabel "set $y$ axis label as you like"
# put extra settings you want to use here
plot sin(x)

We get graph.tex where the graph is drawn.

Then all we have to do is include this file in the main source, say main.tex. Loading gnuplot-lua-tikz package is necessary.


However, executing pdflatex main.tex somehow generates a error saying ! Undefined control sequence. l.7 \gpsetdashtype{gp dt solid} This error occurs on TeX Live 2015, not on my previous environment (i.e. TeX Live 2013) and I am afraid I do not know the reason. Anyway, deleting this line 7, we finally get the following: sine curve

You can, of course, change the detail of graphs by editing graph.tex.

Using gnuplottex package might be a good choice although I have never used it.

Not the answer you're looking for? Browse other questions tagged or ask your own question.