# Fill between two curves in pgfplots.

How to accomplish fill between two curves in pgfplots? For example, I have

...
...


and I would like to have filling between those curves.

-

You can use the \pgfplotstablevertcat command to add the coordinates to your data and then just use the fill option when plotting:

\documentclass{article}
\usepackage{pgfplots}
\usepackage{pgfplotstable}

\begin{document}

\begin{tikzpicture}

% Input the coordinates for the fill boundary, sort them from highest to lowest x value
\pgfplotstablesort[sort cmp={float >}]\coordinates{
0 0
1 1
}

% Concatenate the two series
\pgfplotstablevertcat{\filledcurve}{\data}
\pgfplotstablevertcat{\filledcurve}{\coordinates}

\begin{axis}
% Plot the concatenated tables

% Plot the data and the coordinates for reference
\end{axis}
\end{tikzpicture}

\end{document}


My datafile "data.dat" looks like this

0 2
0.5 -1
1 3


Yielding the following output:

-