Plotpgf skip coords+ each nth

1,084

I guess you meant "you hoped to get" instead of "you expected". each nth point appends an x filter which discards all but each nth input coordinate (as can be written in the manual). And now you add another x filter with skip coords between index={0}{1} which in addition filters away the first point. Thus, you get the same result as before except that the first drawn point is missing.

So I think you have to write your own x filter to do what you want. Another possibility would be to use the mark repeat and mark phase features to accomplish what you want. The downside of this approach is, that the determined axis limits (xmin, xmax, ymin, ymax) also account for the "not shown" points. In case that bothers you, you have to set the values manually.

% used PGFPlots v1.14
    \begin{filecontents}{results.data}
        Move Size Factor
        A 250 30
        B 250 14
        C 250 10
        A 300 40
        B 300 18
        C 300 7
    \end{filecontents}
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
    \begin{axis}[
        only marks,
    ]
        \addplot+ [
            each nth point={3},
        ] table [x=Size,y=Factor] {results.data};
        \addplot+ [
            mark=square,
            mark repeat={3},
        ] table [x=Size,y=Factor] {results.data};
    \end{axis}
\end{tikzpicture}

\begin{tikzpicture}
    \begin{axis}[
        only marks,
    ]
        \addplot+ [
            each nth point={3},
            skip coords between index={0}{1},
        ] table [x=Size,y=Factor] {results.data};
        \addplot+ [
            mark=square,
            mark repeat={3},
            mark phase=2,
        ] table [x=Size,y=Factor] {results.data};
    \end{axis}
\end{tikzpicture}
\end{document}

image showing the result of above code

Share:
1,084

Related videos on Youtube

user3417339
Author by

user3417339

Updated on August 01, 2022

Comments

  • user3417339
    user3417339 over 1 year

    What is the expected behavior of combining the skip coords and each nth command in a pgfplot. Using the following code, I was expected to get a plot with points (250, 30) and (300, 40) and another plot with points (250, 14) and (300, 18).

    Instead the first plot is correct while the second produces only the point (300, 40) as if the two options can't play together.

    \usepackage{filecontents}
    \begin{filecontents}{results.data}
    Move Size Factor
    A 250 30
    B 250 14
    C 250 10
    A 300 40
    B 300 18
    C 300 7
    \end{filecontents}
    
    \begin{figure}[!ht]
        \centering
        \pgfplotsset{tick label style={font=\small}}
        \begin{tikzpicture}
        \begin{axis}[   scale only axis,    yticklabel style={inner sep=0pt, align=right, xshift=-0.1cm}    ]
        \addplot+[color=blue,only marks,mark=*,mark options=solid, mark options={scale=0.4},each nth point={3}]table[x=Size,y=Factor]{results.data};
        \end{axis}
        \end{tikzpicture}
    \end{figure}
    
    \begin{figure}[!ht]
        \centering
        \pgfplotsset{tick label style={font=\small}}
        \begin{tikzpicture}
        \begin{axis}[   scale only axis,    yticklabel style={inner sep=0pt, align=right, xshift=-0.1cm},
        ,skip coords between index={0}{1}
        ]
        \addplot+[color=blue,only marks,mark=*,mark options=solid, mark options={scale=0.4},each nth point={3}]table[x=Size,y=Factor]{results.data};
        \end{axis}
        \end{tikzpicture}
    \end{figure}
    
  • user3417339
    user3417339 over 6 years
    What do you mean by determined? All lowest and highest values will be discarded? I think you put too many addplot+ in the second figure.
  • Stefan Pinnow
    Stefan Pinnow over 6 years
    @user3417339, have a look at the left plot. Remove/comment the second \addplot command and see how "ymin" will change. In both plots I have your and my solution, that is why there are two \addplot commands.
  • user3417339
    user3417339 over 6 years
    Me again, that seems to work pretty well. Let's say I wanted to connect the dots now. When I remove the 'only marks' options, I get a messed up line. Is the Tikz somehow confused by other marks in the data file?
  • user3417339
    user3417339 over 6 years
    I might have encountered further complications. Of course the point of this is to plot much more complicated data. Some of which are missing. Whether I use 'nan' or 'inf' in placeholder of value, all plots subsequent of encountering the first such value are completely out of order by using the next real value.
  • Stefan Pinnow
    Stefan Pinnow over 6 years
    @user3417339, first something general on how this site works: Ask a question as precise as possible to get an answer to your real problem. If the question is answered and it is useful, think of upvoting it and accept the most useful answer (by clicking on the checkmark ✓) that solved your (asked) question. If there is only a minor change in your question, you can edit it accordingly. Otherwise you are free to ask a follow-up question.
  • Stefan Pinnow
    Stefan Pinnow over 6 years
    @user3417339, now to your comments: If you remove only marks that will cause to draw a line to each given coordinate, but only draw the markers at the specified options when you are using "my solution". Maybe that is what is confusing you. Maybe it is easier to see what really happens when you simply draw \addplot {x}; once with and once without "my options".
  • Stefan Pinnow
    Stefan Pinnow over 6 years
    @user3417339, regarding your last comment: Sorry, here I don't have a clue what you want to say. Maybe you ask an aforementioned follow-up question with code that is minimal but showing in general your real use case.