[Tex/LaTex] pgfplots legend: How to remove the line through the marker in the legend

legendpgfplots

I have a plot with a linear line that links up several markers.
The legend entry thus display the marker with a line through it.

Is there a way for the legend entry to display the marker only, without the line through it? i.e., as if it is a legend entry for no line plotting?

Thanks guys.

\begin{tikzpicture}
\begin{axis}[
legend pos=outer north east,
legend cell align={left},
legend entries={abc, def},
scatter/classes={
abc={mark=*,blue},
def={mark=diamond*,red},% <-- don’t add comma
},
]

\addplot [scatter, blue,
point meta=explicit symbolic,
]table [meta=algorithm] {
x y algorithm
50  327 abc
100 659 abc
};
\addplot [scatter, red,
point meta=explicit symbolic,
]table [meta=algorithm] {
x y algorithm
50  172 def
100 308 def
};
\end{axis}
\end{tikzpicture}

Best Answer

I found the answer, by adding 'only marks' to the legend setting. The plots still has a line, but it shows only marker in the legend.

\begin{tikzpicture}
\begin{axis}[
legend pos=outer north east,
legend cell align={left},
legend entries={abc, def},
scatter/classes={
abc={mark=*,blue, only marks},
def={mark=diamond*,red},% <-- don’t add comma
},
]

\addplot [scatter, blue,
point meta=explicit symbolic,
]table [meta=algorithm] {
x y algorithm
50  327 abc
100 659 abc
};
\addplot [scatter, red,
point meta=explicit symbolic,
]table [meta=algorithm] {
x y algorithm
50  172 def
100 308 def
};
\end{axis}
\end{tikzpicture}