# Plots with only a few scattered marks and correct legend

I would like to draw several plots with lines and only a few marks. The markes are irregularely spaced, so I used a method alluded to in the pgfplots manual, section 4.8.5 (Legend appearance), page 159, every legend image post entry. The lines and the marks are created by different \addplot commands. The issue with this method is to have a legend showing both the lines and marks.

Here is an adaptation of the code provided in the pgfplots manual:

\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[legend image post style={mark=*}]
\addplot+[only marks,forget plot]coordinates {(0.5,-0.5) (1,-1) (1.5,-1.5)};

\addplot+[only marks,forget plot]coordinates {(0.3,0.3) (0.45,0.45) (1.7,1.7)};
\end{axis}
\end{tikzpicture}
\end{document}


This code works when there is only one curve because one can specify the plot mark in the legend image post style key. However, do you know how this could be adapted to several plots with different plotmarks ?

-

By providing the legend image post style to each \addplot command instead of to the axis, it only applies to each individual plot:

\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot+[only marks,forget plot]coordinates {(0.5,-0.5) (1,-1) (1.5,-1.5)};
\addplot+[mark=none,smooth,domain=0:2,legend image post style={mark=*}]{-x};

It works indeed. Would there be a way to achieve the same result without having to manualy specify each mark ? Something like legend image post style=has mark so that the legend use the cycle list. –  Alfred M. Aug 31 '12 at 10:48