I'm struggling with getting a custom legend order in my pgfplots groupplot. I tried this (esdd's answer) but I get the error Undefined control sequence. {\patchFailedError}
Stefan Pinnow says one answer later, that it should work the following way:
\documentclass{article}
\usepackage{pgfplots}
\usetikzlibrary{
matrix,
pgfplots.external,
pgfplots.groupplots,
}
\pgfplotsset{compat=1.3}
\tikzexternalize
\begin{document}
\begin{figure}
\tikzset{external/force remake}
\tikzsetnextfilename{ext}
\begin{tikzpicture}
\begin{groupplot}[
group style={
group size= 2 by 1,
xlabels at=edge bottom,
ylabels at=edge left,
x descriptions at=edge bottom,
},
]
\nextgroupplot[]
\addplot [color=black] coordinates {(0,0) (1,0)};
\addplot [color=red] coordinates {(0,1) (1,1)};
\nextgroupplot[name=aa]
\addplot [color=black] coordinates {(0,0) (1,0)}; \label{leg:a}
\addplot [color=red] coordinates {(0,1) (1,1)}; \label{leg:b}
\end{groupplot}
\matrix [
matrix of nodes,
nodes={anchor=west},
anchor=north east,
at={([shift={(-3pt,-3pt)}]aa.north east)},
fill=white,
draw,
inner sep=2pt,
row sep=2pt
] {
\ref{leg:b} $b$ \
\ref{leg:a} $a$ \
};
\end{tikzpicture}
\end{figure}
\end{document}
But I get this output:
Hence, the plot marks are missing. How can I achieve a custom legend order in my case? Disable externalization is no option (also not for this one plot).


pgfplots(1.3)? Recent one is now 1.17 ... – Zarko Mar 27 '21 at 10:02??s instead of the lines. This is because of the\tikzset{external/force remake}. Remove this for the last compilation run and the lines appear. – Stefan Pinnow Mar 29 '21 at 18:35\tikzset{external/force remake}doesn't work properly then. – Steradiant Mar 30 '21 at 06:51