A similar question has been asked here: Pgfplots: let legend show two linestyles
I have a two figures side by side that are plotted in different colors but share the same legend. I would like the legend to have two identical legend images above and below eachother in the respective colors for each entry, but only display the text next to it once. Jesses answer in the above link partly works, but it sets every legend image to whatever is written in 'legend image code', and does not display the marks on the lines. Currently I have settled on making the legend images grey, but its not ideal. How can the answer by Jesse be altered to duplicate each legend image in black and blue, without changing the style at all?
\documentclass{standalone}
\usepackage{amsmath,tikz,pgfplots}
\begin{document}
\begin{figure}[h]
\centering
\begin{tikzpicture}
\begin{axis}[width=0.38\linewidth, height=4cm,xmin=0,xmax=10,ymin=0,ymax=10,
xlabel={x}, ylabel = {y}, title={Black plot}, scale only axis,
legend columns=-1, legend style={at={(0,-0.4)}, /tikz/every even column/.append style={column sep=0.5cm}, legend cell align={left}, anchor=north west}]
\addlegendimage{color=gray, mark=x, dashed, opacity=0.5}
\addlegendimage{color=gray, mark=x, densely dotted, mark options={solid}}
\addlegendimage{color=gray, mark=x}
\addlegendentry{An entry}
\addlegendentry{Another entry}
\addlegendentry{Legend entry three}
\addplot[mark=x, dashed, opacity=0.5, samples=10] {2*x}[color=black];
\addplot[mark=x, densely dotted, mark options={solid}, samples=10] {3*x}[color=black];
\addplot[mark=x, samples=10] {4*x}[color=black];
\end{axis}
\begin{axis}[at={(1.south east)},
xshift=2cm, width=0.38\linewidth, height=4cm,xmin=0,xmax=10,ymin=0,ymax=10,
title={Blue plot},
scale only axis,
xlabel={x},
ylabel={y}]
\addplot[color=blue, mark=x, dashed, opacity=0.5, samples=10] {2*x+2};
\addplot[color=blue, mark=x, densely dotted, mark options={solid}, samples=10] {3*x+2};
\addplot[color=blue, mark=x, samples=10] {4*x+2};
\end{axis}
\end{tikzpicture}
\caption{Caption}
\end{figure}
\end{document}