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}
\addplot
commands? Is this a "real" example so we could also provide a solution that doesn't involve using different layers or is it required to use different layers?"so we could also provide a solution that doesn't involve using different layers or is it required to use different layers"
.reverse legend
to theaxis
options would also do what you want. But it turned out that this also changed the order of the drawn plots, so that is not an option.