6

I'm reading line data from file and plotting it. By default, the curve has markers, where are the original data points. The data points are very uneven, but I would like to have evenly distributed line markers.

MWE (unevenly distributed markers, would like to have for example 5 evenly spaced markers over the whole line):

\documentclass[a4paper,12pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}

\begin{document}
\begin{tikzpicture}
    \begin{axis}
     \addplot[mark=*, blue] coordinates {(1, 1) (2, 1) (3, 1) (5, 1) (8, 1) (16, 1)};
    \end{axis}
\end{tikzpicture}
\end{document}

Any way to accomplish this? Thanks in advance.

  • How is the position of these markers meant to be determined in the case that not all data points are at the same height? – Andrew Swann Jan 14 '15 at 13:18
  • @AndrewSwann Ideal would be when they'd be evenly spaced along the line (i.e. every marker per some constant length of the curve), but I guess evenly in x axis would also suffice in my case. – eimrek Jan 14 '15 at 14:11
6

If I have understood the question correctly, you want to mark the function with markers independently from the data points. Then a decoration helps:

\documentclass[a4paper,12pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}

\usetikzlibrary{decorations}
\usetikzlibrary{decorations.markings}

\begin{document}
\begin{tikzpicture}
  \begin{axis}
    \addplot[
      blue,
      postaction={
        decoration={
          markings,
          mark=between positions 0 and 1 step 0.2
               with { \fill circle[radius=2pt]; },
        },
        decorate,
      },
    ]   
      coordinates {(1, 1) (2, 1) (3, 1) (5, 1) (8, 1) (16, 1)};
    \addplot[
      red,
      postaction={
        decoration={
          markings,
          mark=between positions 0 and 1 step 0.04
               with { \fill circle[radius=2pt]; },
        },
        decorate,
      },
      domain=0:16,
      samples=200,
    ]
      ({\x}, {sin(\x*180/pi)+1});
  \end{axis}
\end{tikzpicture}
\end{document}

Result

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.