The following code gives me the error:
! Package pgf Error: Sorry, the requested layer 'background' is not part of the
layer list. Please verify that you provided \pgfsetlayers and that 'background
' is part of this list.
But background
is in \pgfsetlayers{background,main}
. What am I doing wrong?
\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.14}
\usepgfplotslibrary{fillbetween}
\pgfdeclarelayer{background}
\pgfsetlayers{background,main}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis x line=center,
axis y line=center,
ticks=none
]
\addplot[color=red,domain=-2:2,name path= mycurve]{x^2};
\addplot[domain=-2:2,name path= myline]{x-1};
\begin{pgfonlayer}{background}
\addplot[red!10] fill between [of=myline and mycurve, soft clip={domain=-1:1}];
\end{pgfonlayer}
\end{axis}
\end{tikzpicture}
\end{document}
fill between
setsset layers
which in turn uses another layer set in which nobackground
layer exists. But why do you want to change the default layer where thefill between
stuff is drawn into? And if this should be your goal you could also use the key--valueon layer =<layer name>
to do so.fill between
layers?set layers
is set/active. Could you elaborate your final goal?