# In Tikz, how can I use the fill option on top of a graphics?

In tikzpicture, within an axis environment I am uploading a figure with

\addplot graphics[xmin=0,ymin=-.15,xmax=10,ymax=1.1] {figure.png};


On top of this figure I can draw two lines

\addplot [name path=line1,color=red] table[row sep=crcr]{...data1...};


Now I would normally add a uniform filling between line1 and line2 with

\addplot[blue] fill between[of=line1 and line2];


However this does not work as it is overlapped by the graphics added previously. Is there a way to have the filling overlapping the graphics? How else can I do it?

A MWE would be

\documentclass{article}
\usepackage{pgfplots}
\usepackage{amsmath}
\begin{document}
\begin{figure}
\usepgfplotslibrary{fillbetween}
\begin{tikzpicture}
\begin{axis}[xmin=0,ymin=0,xmax=4,ymax=16]
table[row sep=crcr]{%
0   0\\
1   1\\
2   4\\
3   9\\
4   16\\
};
table[row sep=crcr]{%
0                   0\\
1                   1\\
2                   2\\
3                   3\\
4                   4\\
};
\end{axis}
\end{tikzpicture}%
\end{figure}
\end{document}

• Welcome to TeX.SX! The first thing you should do is adding a minimal working example (MWE) that illustrates your problem. Reproducing the problem and finding out what the issue is will be much easier when we see compilable code, starting with \documentclass{...} and ending with \end{document}. – CarLaTeX Feb 22 '17 at 16:40
• Perhaps you could have a look at the on layer key (section 4.27.3 * Changing the Layer of Graphical Elements* in the manual). – Torbjørn T. Feb 22 '17 at 16:42

It is sufficient to add on layer=axis background in the options of addplot. The following code would work

\documentclass{article}
\usepackage{pgfplots}
\usepackage{amsmath}
\begin{document}
\begin{figure}
\usepgfplotslibrary{fillbetween}
\begin{tikzpicture}
\begin{axis}[xmin=0,ymin=0,xmax=4,ymax=16]
table[row sep=crcr]{%
0   0\\
1   1\\
2   4\\
3   9\\
4   16\\
};
table[row sep=crcr]{%
0                   0\\
1                   1\\
2                   2\\
3                   3\\
4                   4\\
};