this is a follow up question to: Gap between line and point in pgfplots, like pointintervalbox in gnuplot. I would like to add a legend in the plot and maybe even on the y-axis. Unfortunatelly this does not work with the "discontinuous line" code:
\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
\makeatletter
\pgfplotsset{
discontinuous line/.code={
\pgfkeysalso{mesh, shorten <=#1, shorten >=#1}
\def\pgfplotsplothandlermesh@VISUALIZE@std@fill@andor@stroke{%
\pgfplotspatchclass{\pgfplotsplothandlermesh@patchclass}{fill path}%
\pgfplotsplothandlermesh@definecolor
\pgfusepath{stroke}
\pgfplotsplothandlermesh@show@normals@if@configured
}%
},
discontinuous line/.default=1.5mm
}
\makeatother
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis background/.style={
shade,bottom color=gray!50,top color=white
},
legend pos=north west,
xlabel=$x$,
ylabel=\ref{dataone}\ one \ref{datatwo}\ two
]
\addplot [discontinuous line, black, mark=*] table {
0 5
1 3
2 4
3 8
4 0
};
\label{dataone}
\addlegendentry{one}
\addplot [discontinuous line=3mm, red, mark=square] table {
0 1
2 5.5
3 7.25
4 8
};
\label{datatwo}
\addlegendentry{two}
\end{axis}
\end{tikzpicture}
\end{document}
Which gives this result:
Does anyone have an idea how to get the correct legend? Thanks and greetings!

