[Tex/LaTex] How to plot mark on every nth point

pgfplots

I have a long CSV data file:

x,y1,y2...
1,v1,v1...
2,v2,v2...
....

I use pgfplots to plot all the lines. I also want to add mark shapes. But the problem is that the data is too dense, and I have a limited space, so the marks stick together.

I tried:

 \addplot[blue, thin, mark=square, each nth point=20] table ...

But it also skipped the data points.

I want to have a smooth line, but only a few marks. How can I do that?

Best Answer

You need to use mark repeat key to repeat marks at frequent intervals. mark phase will tell at which point the marks should start. For example,

make repeat = r,
mark phase = p

will put the mark first at pth point and then at p+r th and then p+2rth point etc. An example from the manual

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
\begin{document}
  \begin{tikzpicture}
\begin{axis}[title=Without \texttt{mark repeat}]
\addplot+[scatter,samples=100] {sin(deg(x))};
\end{axis}
\end{tikzpicture}
\begin{tikzpicture}
\begin{axis}[title= With \texttt{mark repeat=5,mark phase=7}]
\addplot+[scatter,samples=100,
mark repeat=5,mark phase=7]
{sin(deg(x))};
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

Related Question