데이터 파일을 강제로 다시 읽습니다.

데이터 파일을 강제로 다시 읽습니다.

동일한 축에 홀수/짝수 행을 별도로 플롯하려는 데이터 파일이 있습니다. 그러나 table옵션은 데이터를 읽을 때 한 번만 적용되는 것으로 보입니다. 이는 축당 한 번만 발생합니다(즉, \nextgroupplot데이터를 다시 읽은 후 또는 새 에서 읽은 것처럼 보입니다 tikzpicture).

\documentclass{article}
\usepackage{pgfplots}
\begin{filecontents}{data.dat}
1 1
2 4
3 3
4 8
\end{filecontents}
\begin{document}

\begin{tikzpicture}
    \begin{axis}
        \addplot[no markers] table[each nth point=2]{data.dat};
        \addplot[only marks] table[each nth point=2, skip first n=1]{data.dat};
    \end{axis}
\end{tikzpicture}

should be:

\begin{tikzpicture}
    \begin{axis}
        \addplot[no markers] table{
            1 1
            3 3
        };
        \addplot[only marks] table{
            2 4
            4 8
        };
    \end{axis}
\end{tikzpicture}
\end{document}

table각 명령 에 대해 데이터를 강제로 다시 읽는 옵션이 있습니까 ?

결과

답변1

테이블을 읽거나 조판하기 위한 키 skip first n이기 때문에 키를 사용하여 유연한 방식으로 좌표를 필터링 할 수는 없다고 생각합니다 . pgfplotstable대신 필터를 사용하여 홀수/짝수 행을 제거할 수 있습니다.

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}
\begin{filecontents}{data.dat}
1 1
2 4
3 3
4 8
\end{filecontents}
\begin{document}


\begin{tikzpicture}
    \begin{axis}
        \addplot[no markers,each nth point=2] table {data.dat};

        \addplot[only marks,x filter/.code={
                    \ifodd\numexpr\coordindex+1\relax
                        \def\pgfmathresult{}
                    \fi}
                ] table {data.dat};
    \end{axis}
\end{tikzpicture}

\end{document}

여기에 이미지 설명을 입력하세요

물론 이 코드를 사용하면 ( Mod(,)등을 사용하여) 자신만의 필터를 만들 수 있으므로 어쨌든 가능합니다.

관련 정보