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 \includegraphics ? This will generally speed up compilation, and graphs thus generated are probably more customisable and so on.

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...

Yes, there are good reasons for doing this within LaTeX: (a) less files to handle, (b) greater ease if you make edits, (c) possibility to conditionally change parameters in the plot.
–
Hendrik VogtOct 2 '10 at 11:57

1

(d) The text in your graphics is handled by the same typesetting engine that is handling the text in your paper which makes it look cohesive, professional and very very sexy.
–
SharpieApr 12 '11 at 5:13

1

None of those reasons tell against using Sweave...
–
SeamusApr 15 '11 at 10:23

Sweave seems like the natural answer. Less code, and once you learn it you're set up to do much more besides function graphs.
–
isomorphismesSep 9 '11 at 17:02

Usually I point it to the same folder as the working LaTeX document, and put it in the document

\input{rgraph}

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.

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.