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.
% 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
gnuplotat 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-escapein 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
\usepackage[miktex]{gnuplottex} \usepackage{tikz} \usepackage{gnuplot-lua-tikz} \usepackage{mathpazo}f) In your TeX document where you want your plot to appear do some kind like this
\begin{gnuplot}[scale=0.95,terminal=lua] set parametric set angle degree set urange [0:360] set vrange [-90:90] fx(u,v)=cos(u)*cos(v) fy(u,v)=sin(u)*cos(v) fz(v)=sin(v) splot fx(u,v),fy(u,v),fz(v) \end{gnuplot}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.
Скажите, пожалуйста, как построить график функции f(x,y)= x^2+y^2 для Tikz? Спасибо вам большое!
Post a comment