Which is the best way to put function graphs into a LaTeX document?
|
|
To extend the answer from Mica,
or using GNUplot:
You can also pre-calculate values using another program, for example a spreadsheet, and import the data. This is all detailing in the manual. |
|||||||
|
|
tikz + gnuplot (see the manual for details). Here's a "live" example used in a lecture (using beamer) to illustrate the convergence of a series of square-integrable functions.
|
|||||||||
|
|
OK, here's a non-TikZ answer for balance (you'd think TikZ is the second coming on SE!)
|
|||||||||||||||||
|
|
Further possibilities are pst-plot or Asymptote via the asymptote package. Not so good (because of less consistency) would be gnuplottex. |
|||||||||
|
|
The latest version of gnuplot itself also has a tikz output terminal |
||||
|
|
|
Vincent Zoonekynd gives an example for this, from his long list of Metapost examples:
beginfig(166)
ux:=2mm;
uy:=5mm;
numeric xmin, xmax, ymin, ymax, M;
xmin := -6.3; xmax := 12.6;
ymin := -2; ymax := 2;
M := 100;
draw (ux*xmin,0) -- (ux*xmax,0);
draw (0,uy*ymin) -- (0,uy*ymax);
pair a[];
for i=0 upto M:
a[i] := (
xmin + (i/M)*(xmax-xmin),
sind(180/3.14*( xmin + (i/M)*(xmax-xmin) ))
) xscaled ux yscaled uy;
endfor;
draw a[0] for i=1 upto M: --a[i] endfor;
endfig;
gives This is much longer than the other examples, because it does everything from scratch, but it would be easy to put some functions for creating axes and scaling the graph, so that specifying the plot was some boilerplate plus the function definition. I might do that later... |
||||
|
|
|
Is there a specific reason you need to graph the function within LaTeX? wouldn't it be better to use something like R or matlab to generate a pdf that you can then If you absolutely have to generate the graph inside LaTeX then consider using the standalone package: this will save some time when compiling big documents... Then of course, there is sweave... |
|||||||||||||
|
|
R and sweave were already mentioned but I couldn't pass up the opportunity to mention tikzDevice (yes, again tikz). I have successfully been using it to generate .tex documents with R, for example
Usually I point it to the same folder as the working LaTeX document, and put it in the document
I feel this gives me much needed control over my graphs, although I'll have to try some other solutions here before I decide which solution is the most comfortable for me. Just thought I'd add something (hopefully) of value. |
||||
|
|
|
edit: Oops — I thought you meant graph-theory graphs, not plots of ƒ(x) versus x. I would use |
||||
|
|
|
Just to add to the mentioning of R and matlab, if you are familiar with Python, I would suggest the matplotlib library in conjunction with numPy. I use these (in addition to org-mode for emacs) all the time for publication quality plots. |
||||
|
|




