How to create the graph only once in Tikz/pgf/pgfplots

I saw Why is tikz so much slower when plotting a huge amount of data than WYSIWYG plotting tools? that pgfplots can be configured to do the plotting only once. How to do this? I have a document with many graphs and repeated runs takes so much time.

-
See Section 32 Externalization Library of the tikz/pgf manual. Basically \usetikzlibrary{external} \tikzexternalize should be all you need. –  Peter Grill Apr 3 '12 at 23:56
Thanks for the reply. It does work. But I have a small problem. Every time I run pdflatex, it stops in between saying that the system call 'pdflatex -shell-escape -halt-on-error -interaction=batchmode -jobname "pami2012-figure2" "\def\tikzexternalrealjob{pami2012}\input{pami2012}"' did NOT result in a usable output file 'pami2012-figure2' (expected one of .pdf:.jpg:.jpeg:.png:). Please verify that you have enabled system calls. Actually I have enabled write18 and the pdf of each of the figures are produced also. I manage by pressing 's', but how to avoid that? –  suresh Apr 4 '12 at 0:20
It would be helpful if you would compose a fully compilable MWE that illustrates the problem including the \documentclass and the appropriate packages. This will also serve as a test case and ensure that the solution actually works for you. In the mean time, perhaps try adding -enable-write18 and ensure that you do not have older .aux files lying around. –  Peter Grill Apr 4 '12 at 0:24
It is fine now. There was another error (file missing) which caused this behavior I guess. But that error did not show up instead the previous one (the one I posted earlier) showed up. Thanks again. It is difficult to imagine when one quickly thumbs through the pgf manual that it is the externalization library that is needed. –  suresh Apr 4 '12 at 0:28