I have gone through previous questions [1,2,3], but I still couldn't figure out how to draw plots on different layers and change their order of drawing.
For this MWE, I would be grateful if I could figure out how to change the order of appearance of the three plots in such a way that the legend entries have the same order while keeping the plots commands/definitions in the same order as much as possible.
\RequirePackage{luatex85}
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
legend style={
at={([yshift=30pt]0.5,1)},
anchor=north},
legend columns=-1,
xmin=0, xmax=10,
ymin=0, ymax=10,
]
%
\addplot [red, line width = 5pt, domain=0:10] {x}; \addlegendentry{$x$}
\addplot [black, line width = 5pt, domain=0:10] {(x-5)^2}; \addlegendentry{$(x-5)^2$}
\addplot [yellow, line width = 5pt, domain=0:10] {10-(x-5)^2}; \addlegendentry{$10-(x-5)^2$}
\end{axis}
\end{tikzpicture}
\end{document}
Best Answer
In case you really should need to plot the
\addplot
s on different layers, have a look at the following code.For more details on how the solution works, please have a look at the comments in the code.