9

I am trying to add a few markers to a curve with lots of points, like shown below, but without resorting to the second addplot:

\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}
  \addplot[color=red,no markers] coordinates {
    (2,-1.8559703)
    (2.5,-2.8559703)
    (3,-3.5301677)
    (3.5,-4.01677)
    (4,-4.3050655)
    (4.5,-4.813136)
    (5,-5.1413136)
    (5.5,-5.7322865)
    (6,-6.0322865)
    (6.5,-6.675052)
    (7,-6.9675052)
    (7.5,-7.975052)
    (8,-8.9377747)
  };
  \addplot[color=red, only marks] coordinates {
    (2,-1.8559703)
    (4,-4.3050655)
    (6,-6.0322865)
    (8,-8.9377747)
  };
\end{axis}
\end{tikzpicture}
\end{document}
12

You have several keys allowing to control which markers should be drawn:

  1. You can use mark repeat=<number>; this allows to draw only each nth mark where n was the value provided as <number>.

  2. mark phase=<number>; add this after using mark repeat to control the starting point for the markers.

  3. There also mark indices={<index list>}; use this to specify the index list of markers that should be drawn.

A complete example showing those keys in action (the first example gives the marking schema you requested in your question):

\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}
  \addplot+[color=red,mark repeat=4] coordinates {
    (2,-1.8559703)
    (2.5,-2.8559703)
    (3,-3.5301677)
    (3.5,-4.01677)
    (4,-4.3050655)
    (4.5,-4.813136)
    (5,-5.1413136)
    (5.5,-5.7322865)
    (6,-6.0322865)
    (6.5,-6.675052)
    (7,-6.9675052)
    (7.5,-7.975052)
    (8,-8.9377747)
  };
\end{axis}
\end{tikzpicture}

\begin{tikzpicture}
\begin{axis}
  \addplot+[color=red,mark repeat=3,mark phase=2] coordinates {
    (2,-1.8559703)
    (2.5,-2.8559703)
    (3,-3.5301677)
    (3.5,-4.01677)
    (4,-4.3050655)
    (4.5,-4.813136)
    (5,-5.1413136)
    (5.5,-5.7322865)
    (6,-6.0322865)
    (6.5,-6.675052)
    (7,-6.9675052)
    (7.5,-7.975052)
    (8,-8.9377747)
  };
\end{axis}
\end{tikzpicture}

\begin{tikzpicture}
\begin{axis}
  \addplot+[color=red,mark indices={1,5,9}] coordinates {
    (2,-1.8559703)
    (2.5,-2.8559703)
    (3,-3.5301677)
    (3.5,-4.01677)
    (4,-4.3050655)
    (4.5,-4.813136)
    (5,-5.1413136)
    (5.5,-5.7322865)
    (6,-6.0322865)
    (6.5,-6.675052)
    (7,-6.9675052)
    (7.5,-7.975052)
    (8,-8.9377747)
  };
\end{axis}
\end{tikzpicture}

\end{document}

enter image description here

| improve this answer | |

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.