There are some question regarding how to plot an area under a curve with pgfplots. But as far as I can see, all the answers have in common that a function has to be plotted twice with different style options. Example, Pgfplots: how to fill the area under a curve with oblique lines (hatching) as a pattern?
That's also the way I do it currently. Here is an easy working example to play with:
\begin{tikzpicture}[/pgf/declare function={f=1-exp(-x*x);}]
\begin{axis}[axis x line=center]
\addplot [domain=-2:2, samples=500, red, fill] {f} \closedcycle;
\addplot [domain=-5:5, samples=500] {f};
\end{axis}
\end{tikzpicture}
But especially if one has many plots with non-trivial functions (needing a lot of samples to look smooth!) this can lead to long compile times.
Just setting down the samples for the area filling plot often is not enough, because then some of the area will "overhang" on the wrong side of the curve due to the rough sampling of the plot.
Is it possible to achieve the same output with just plotting the function once to significantly reduce the compile time?

external. – Marco Daniel Apr 25 '13 at 08:50