[Tex/LaTex] Modify the legend-style in pgfplots

legendpgfplots

I have a question concerning pgfplots. I made a minimal example which is related to the example in the pgfplots manual (page 182):

\documentclass{standalone}

\usepackage{tikz}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
\begin{axis}[legend image post style={mark=*}]

\addplot+[mark=*, color=blue, very thin, only marks, mark size=0.8pt]{-x*(x-2)};
\addlegendentry{Measurment}
\end{axis}
\end{tikzpicture}

\end{document}

Output:

enter image description here

I want to modify the symbol of the legend (here: {mark=*}) in such a way, that I have a line in the legend. Have a look on this example:

\documentclass{standalone}

\usepackage{tikz}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
\begin{axis}[legend image post style={mark=}]


\addplot+[mark=*, color=blue, very thin, mark size=0.8pt]{-x*(x-2)};
\addlegendentry{Measurment}
\end{axis}
\end{tikzpicture}

\end{document}

Output:

enter image description here

Here, the legend is a line, exactly how I want to have it. But I do not want to have line in the diagram itself. How can I solve this problem?

Best Answer

here you go:

\documentclass{article}

\usepackage{tikz}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
\begin{axis}

\addplot+[
legend image post style={sharp plot, line width=1pt, mark=none},
mark=*,
color=blue,
very thin,
only marks,
mark size=0.8pt
]
{-x*(x-2)};
\addlegendentry{Measurment}
\end{axis}
\end{tikzpicture}

\end{document}
Related Question