PGF/TikZ provides a convenient mechanism for plotting functions using GNUPLOT. To run this example for the first time you have to do the following:
PGF will call GNUPLOT for you and store the data in a file. Next time you compile the example, data will be loaded from the generated file. See section 11.12.3 in the manual for more information.
Do you have a question regarding this example, TikZ or LaTeX in general? Just ask in the
LaTeX Forum.
Oder frag auf Deutsch auf TeXwelt.de.
En français: TeXnique.fr.
% Author: Till Tantau% Source: The PGF/TikZ manual\documentclass{article}\usepackage[latin1]{inputenc}\usepackage{tikz}% GNUPLOT required\begin{document}\pagestyle{empty}\begin{tikzpicture}[domain=0:4] \draw[very thin,color=gray] (-0.1,-1.1) grid (3.9,3.9); \draw[->] (-0.2,0) -- (4.2,0) node[right] {$x$}; \draw[->] (0,-1.2) -- (0,4.2) node[above] {$f(x)$}; \draw[color=red] plot[id=x] function{x} node[right] {$f(x) =x$}; \draw[color=blue] plot[id=sin] function{sin(x)} node[right] {$f(x) = \sin x$}; \draw[color=orange] plot[id=exp] function{0.05*exp(x)} node[right] {$f(x) = \frac{1}{20} \mathrm e^x$};\end{tikzpicture}\end{document}
Comments
Hi, I'm trying to use this code but I get error messages:
Package pgf Warning: Plot data file `index.x.table' not found. on input line 16.
Package pgf Warning: Plot data file `index.sin.table' not found. on input line 18.
Package pgf Warning: Plot data file `index.exp.table' not found. on input line 20.
I tried to compile using the command:
latex myfile.tex --shell-escape
@Rafael. Have you checked that gnuplot is available? Try typing
gnuplot
at the command line.Rafael,
Try putting the filename after -shell-escape:
latex -shell-escape myfile.tex
(I get the same error if I put -shell-escape after the filename. Also, despite the instructions above, the latex documentation tells me to use -shell-escape, not --shell-escape, though it seems to accept both.)
If that still doesn't work, a horrible workaround is to run latex, run gnuplot by hand ("gnuplot *.gnuplot"), and then run latex again.
I suffered from the same error for a while, found the offending write18 command in pgfmoduleplot.code.tex, thought, "They should really point out in the documentation that you need to enable shell escapes," and then felt really dumb after seeing it was there all along. For the sake of others who neglect the instructions, I would suggest a more detailed error message, like "Plot data file `#1' not found. Perhaps you need to enable shell escapes with '-shell-escape' or '-enable-write18'?"
Chris H.
You can also enable shell escape by putting the following line at the top of your document:
Another word of warning:
The automatic gnuplot function doesn't work if -aux-directory is set. The ".gnuplot" file(s) are correctly written in the aux directory, but are not correctly passed through gnuplot to generate the ".table" file(s).
This seems to be noticed here:
http://www.archivum.info/fr.comp.text.tex/2008-01/msg00562.html
i also have same problem, i have install gnuplot this in vista. How to know that my gnuplot has working or not. Please inform me, as i am windows user only. the axis is shown, but line curve line isnot shown after compillation.
Using -shell-escape and -enable-write18 works for me but putting
%& -shell-escape -enable-write18
at the top of the document does not work.
@rafael thank a lot, it is work!!! your suggestion to use:
%& -shell-escape -enable-write18
can resolve the problem. my computer configuration: MS Vista SP1, Miktex 2.7 and Texmaker 1.8, installed with pgf/tikz and gnuplot
maybe if the else who have same problem can use this way..
thank you very much, rafael
after success in Vista, I tried to use the same solution for Microsfot XP SP2, with Miktex 2.7 and Texmaker 1.8. It didn't work. I have tried to write "%& -shell-escape " , also " -enable-write18 " and " %& -shell-escape -enable-write18 " on the top of ducument. Anybody can help me?
i can use gnuplot now. The solution are:
%& -shell-escape
in the top of your *.tex document.try pdflatex instead latex.
thank you very much, hendri, i had the same problem and it worked for me, too :)
I change my computer with Win XP sp3 japanese version, Texmaker 1.9.2, Miktex 2.7. I can`t run gnuplot anymore as I succeed do that in previous my WinXP and Win Vista PC.
The error message show: "file *.table not found" Anybody can help me?
I have to use
%& --shell-escape dubble -- in front of shell
as the first line of my latex-file (miktex 2.7)
Hi, the magic command:
%& --shell-escape dubble
works on my Vista !
Thanks
Bogdan
I renamed wgnuplot.exe on Win Vista to gnuplot.exe and added the path to the binary as suggested, also used the --shell-escape commandline argument, but it would not work either.
The problem was fixed renaming pgnuplot.exe to gnuplot.exe
Hi,
Is it possible to do gnuplot splot with PGF/TikZ ?
I want to have equivalent PGF/TikZ code for following gnuplot code. At the moment I'm using the gnuplottex package but because it only works in monochrome the result looks ugly as hell.
As far as I know, PGF can't plot 3D-plots generated by GNUPLOT. You could try the GNUPLOT TikZ terminal. You should also check out pgfplots. The development version may have support for 3D-plots.
The GNUPLOT TikZ terminal works fantastic! At the moment I'm fiddling with the gnuplottex package code so I can have the GNUPLOT script commands inline in a TeX document and have the whole thing (text & gnuplot graphics) 'compiled' in one pass.
Just for the record : For ppl who are using windows ... at the moment the experimental MinGW compiled gnuplot with TikZ/lua support from the gnuplot page is broken :s (server error). You can download a GNUPLOT version that works from http://peter.affenbande.org/gnuplot/
PS : pgfplots doesn't do 3D graphics either
Update :) For all who had/have the same problem like me plotting 3D graphics with GNUPLOT in (pdf)TeX with inline code in color on windows (MikTeX) this mini howto (I could'nt find hints on the net, that's why I'm putting this in this comment)
a) download the patched gnuplot windows executable from peter affenbande his site (see previous post)
b) rename pgnuplot.exe to gnuplot.exe and put the executable gnuplot.exe in a directory that's included in the windows path environment (I use c:\ windows\ system32)
c) Download gnuplot.lua & gnuplot-lua-tikz.sty from peter affenbande his site. Place both these files in the directory where you're TeX document on which you're working resides.
d) Configure TeX so that shell escape is allowed (in TeXnicCenter for example add --shell-escape --enable-write18 as argument to pdflatex.exe in the output profile LaTeX=>PDF (Alt-F7)
e) In the preamble of your document add folowing lines
f) In your TeX document where you want your plot to appear do some kind like this
Works like a charm, now you have a) color plots without using pstricks and/or pst-pdf b) the possibility to have 3D plots c) the possibility to use TikZ code in your plots d) you don't have to make the plots by hand e) all is made in only one run ...
Happy plotting !
Thank you Herman for the detailed write-up. Really useful.
At least after month passed, I can call gnuplot. The secret is have to change the name of file into one word only. For example: file name "progress report.tex" have to change into "progressreport.tex" . Then I write %& --shell-enable at the top of document as suggested by others. That is all. I hope I can help somebody who has same problems.
If you have problems using newer versions of Gnuplot, you should install the latest version of PGF from CVS. Recently a compatibility issue with newer version of Gnuplot was fixed. You can download recent builds from the builds section of this site.
when i give the command plot "force.dat" using 1:2 title "A"
it gives a warning: skipping unreadable file "trail.xls" , no data in the plot
what may be the possible reasons for this? how to solve this problem? how to read the data values from a table made under file with .xls(excel sheet)?? pls do help
Hey, cool thing! But how am I able to use LaTeX or even Tikz inside of \begin{gnuplot}\end{gnuplot}? $\alpha$ doesn't work...
@Sam. Check out the Gnuplot TikZ terminal site for examples.
@Nham Ngoc Tan. When you've done all the stuff Herman described in this post, you can just write this:
%& -shell-escape \documentclass[a4paper]{article}
\usepackage[miktex]{gnuplottex} \usepackage{tikz} \usepackage{gnuplot-lua-tikz} \usepackage{mathpazo}
\begin{document}
\begin{gnuplot}[terminal=lua] splot xx + yy \end{gnuplot}
\end{document}
Does anybody know how to draw an implicit function like x^3 + y^3 - 2xy with tikz and gnuplot? The idea is to define this function as a 3-D surface and then find an intersection curve with z=0 plane. But how to do this?
I'm constantly getting the error in gnuplot that the terminal table is unknown... indeed when I type "set term" no table is to be found.. how do I install this function in gnuplot so that it does have the table terminal?
@rommel The problem is that
set terminal table
is deprecated in recent versions of GNUPLOT (from 2005 and newer). You either have to use an old version of GNUPLOT, or install a recent development build of TikZ.On a Mac you have to use fink to install gnuplot. Because only the fink-gnuplot provides the terminal called table. This is nessesary to run it with texshop (maybe also with textmate)
rommel, I guess you can use 'set table "outputfile"' instead. Look at 'help set table'.
No puedo hacer que TexNicCenter encuentre y use el programa GNUPLOT, ¿como? tengo que configurar TexNicCenter para que funcione?
I used the following bat file on a windows7 system to get to call gnuplot from latex:
latex --enable-write18 --shell-escape thesis.tex bibtex thesis latex --enable-write18 --shell-escape thesis.tex latex --enable-write18 --shell-escape thesist.tex dvips -Ppdf thesis.dvi -o ps2pdf thesis.ps
Give it a try and let me know whether this works for you, too! Philipp
latex --enable-write18 --shell-escape thesis.tex
bibtex thesis
latex --enable-write18 --shell-escape thesis.tex
latex --enable-write18 --shell-escape thesis.tex
dvips -Ppdf thesis.dvi -o ps2pdf thesis.ps
I'm confused by several things. I installed MacTeX 2009 with OS X 10.6.4 and gnuplot 4.4 (from gnu.org, not through fink). Gnuplot by itself works fine. But I could not run this example successfully; the log file contained messages like were
runsystem(gnuplot gnuplot-basics.x.gnuplot)...disabled.
and
Package pgf Warning: Plot data file `gnuplot-basics.x.table' not found
Through some searching - including the helpful posts in this forum, I found that I needed to install the lua library (worked), configure gnuplot with the command
./configure --with-readline=builtin
add the line
%& -shell-escape
as the first line in the example tex file, and execute
pdflatex --enable-write18 --shell-escape gnuplot-basics.tex
That resolved some issues; now the log file contained messages like
runsystem(gnuplot gnuplot-basics.x.gnuplot)...executed.
but I still get
Package pgf Warning: Plot data file `gnuplot-basics.x.table' not found
and I also see the following on the screen:
"gnuplot-basics.x.gnuplot", line 1: unknown or ambiguous terminal type; type just 'set terminal' for a list
And indeed, gnuplot does not list 'table' as a terminal.
What else am I doing wrong? I can't seem to get any helpful information on any other sites and would very much appreciate any help. Thanks!
Just wanted to let everyone know that I fixed this problem thanks to a very helpful piece of advice I got on comp.text.tex. Apparently, there's an incompatibility between gnuplot 4.4 and TikZ. By modifying line 288 in
pgfmoduleplot.code.tex
(in my case, located at: /usr/local/texlive/2009/texmf-dist/tex/generic/pgf/modules/pgfmoduleplot.code.tex)
from
\xdef\pgf@gnuplot@head#1{set terminal table; set output...
to
\xdef\pgf@gnuplot@head#1{set table; set output...
did the trick. Hope this helps other people, too.
Thank you #38, works like a charm. Or, as we Finns say, works like a train's toilet :-).
(In my case the file was located at /usr/local/texlive/2008/texmf-dist/tex/generic/pgf/modules/pgfmoduleplot.code.tex)
I was wondering if anyone could kindly help me here. I have gnuplot installed, as well as the latest TikZ/PGF build. My plots don't show up when I typeset in TexShop, although the gnuplot files are being produced in the directory. And there are no error messages either. The plot just refuses to display. The rest of TikZ works fine. What could be the problem? I have used the --shell-escape line to no avail.
Thanks!
OK, so I'm getting these errors:
"Lesson2-3RelationsandFunctions3.x.gnuplot", line 1: unknown or ambiguous terminal type; type just 'set terminal' for a list
Package pgf Warning: Plot data file `Lesson2-3RelationsandFunctions3.x.table' n ot found. on input line 92.
By the way, "Lesson2-3RelationsandFunctions3" is my latex file. "x" is the plot id in my case.
What could be the problem?
Thanks, JO
Thank you Nut!!!
The manual change in /usr/local/texlive/2009/texmf-dist/tex/generic/pgf/modules/pgfmoduleplot.code.tex certainly fixes things ;)
When I tried this code, this happened: http://dl.dropbox.com/u/43767810/graphs.pdf . More complicated gnuplot examples didn't work too. It seems like "plot[]" doesn't do anything for me. No error messages.
@dennis, I am in the same boat as you. I have done everything suggested and ask and nothing works. I have the same setup as well TC and miktex.
Yes. I have a MAC OSX and no way the gnuplot works with Tikz. Tikz generate .gnuplot files but after that gnuplot doesn't generate .tables. I have to run gnuplots by hand to generate de .tables and this way it works. I tried everithing on these posts. The pgfmoduleplot.code.tex in my version (TL2012) comes already fixed. Just to make a point of the situation. Thank you all.
To get MAC OSX gnuplot to work with Tikz I did the following:
first line of the tex file: %& -shell-escape
in the terminal ran the command: pdflatex --enable-write18 --shell-escape filename.tex
I installed gnuplot with homebrew and doing those two things got rid of the .table error for me.
Adding comments is currently not enabled.