5

I have a number of large data files with x rows in the range of 0 to z. Is there an easy way to set a different marker at specific intervals using pgfplots/TikZ? How can I produce a figure such that the marker for the plot at intervals 0, 10, 20, ..., z is for example a cross but a circle for the rest of the points?

Here's a MWE that can get you started:

\documentclass{article}

\usepackage{tikz,pgfplots}
\pgfplotsset{compat=1.8}

\begin{filecontents*}{thePlot.dat}
x y
0 20.44
1 20.06
2 19.76
3 19.54
4 19.40
5 19.34
6 19.36
7 19.46
8 19.64
9 19.90
10  20.24
\end{filecontents*}

\begin{document}
  \begin{figure}[]
    \centering
    \begin{tikzpicture}
      \begin{axis}[
        xlabel={$x$},
        ylabel={$y$},]

        \addplot+[only marks,mark=x]
          table[x=x,y=y] {thePlot.dat};
      \end{axis}
    \end{tikzpicture}%
    \caption{The caption.}
  \end{figure}
\end{document}

1 Answer 1

5

You can adapt the code given in PGFplots marks mandatory for 1st and last point

\documentclass[border=5mm]{standalone}

\usepackage{tikz,pgfplots}
\pgfplotsset{compat=1.8}

\pgfplotsset{
    mark repeat*/.style 2 args={
        scatter,
        scatter src=x,
        scatter/@pre marker code/.code={
            \pgfmathtruncatemacro\usemark{
                mod(\coordindex,#1)==0
            }
            \ifnum\usemark=1
                \pgfplotsset{mark=#2}
            \fi
        },
        scatter/@post marker code/.code={}
    }
}

\begin{filecontents*}{thePlot.dat}
x y
0 20.44
1 20.06
2 19.76
3 19.54
4 19.40
5 19.34
6 19.36
7 19.46
8 19.64
9 19.90
10  20.24
\end{filecontents*}

\begin{document}
    \begin{tikzpicture}
      \begin{axis}[
        xlabel={$x$},
        ylabel={$y$},]

        \addplot+[only marks, mark=o, mark repeat*={5}{x}]
          table[x=x,y=y] {thePlot.dat};
      \end{axis}
    \end{tikzpicture}
\end{document}
1
  • 2
    Thank you so much, Jake. Once again you save the day. If you keep this up, you're going in my thesis acknowledgements. :-)
    – sudosensei
    Aug 16, 2013 at 6:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .