強制重新讀取資料文件

強制重新讀取資料文件

我有一個數據文件,我想在同一軸上分別繪製奇數/偶數行。但這些table選項似乎只適用一次,在讀取資料時,每個軸只發生一次(即在 a 之後,\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 nkey 以靈活的方式過濾座標,因為它是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(,)等),因此無論如何它都是可行的。

相關內容