foreach ループ内の複数の "\immedite\write" からの } エラーが見つかりません。gnuplot で現在のプロットに座標エラーがありません

foreach ループ内の複数の "\immedite\write" からの } エラーが見つかりません。gnuplot で現在のプロットに座標エラーがありません

これらのエラーは、マスター データ ファイルをループして再構成し、新しく作成したファイルを pgfplots の引数として渡せるようにするコード セクションから発生しているのではないかと考えています。このセクションを で囲むと、\iffalse...\fi「不足している }」エラーはなくなり、gnuplot の警告「現在のプロットには座標がありません」が表示されます。ただし、pgfplots は同じデータ ファイル (おそらく問題の原因となっている foreach ループを使用して作成されたもの) を使用し、レンダリングは正常に行われます。}の後にを追加してみました\end{axis}が、エラーは修正されませんでした。また、 の直前に を追加してみましたが、これにより「余分な }」エラーが発生します。

\documentclass{article}
\usepackage{pgfplots, pgfplotstable}
\usepackage{filecontents}
\usepackage{indentfirst}
\usepackage{amsmath}
\usepackage{float}
\usepackage{hhline}
\usepackage{multirow}
\usepackage{datatool}
\usepackage{booktabs}
\usepackage[strict]{changepage}
\usepackage[position=top]{subfig}

\begin{filecontents}{data.dat}
28.7 28.4 43.4
0.2416 0.2415 nan
0.2420 0.2416 nan
0.2421 0.2416 nan
0.2416 0.2422 nan
0.2410 0.2422 nan
35.9 35.6 50.4
0.2695 0.2691 nan
0.2679 0.2691 nan
0.2691 0.2697 nan
0.2691 0.2691 nan
0.2686 0.2694 nan
42.6 42.3 57.4
0.2951 0.2953 nan
0.2950 0.2951 nan
0.2952 0.2956 nan
0.2951 0.2957 nan
0.2951 0.2954 nan
47.2 46.9 61.9
0.3091 0.3104 nan
0.3095 0.3107 nan
0.3106 0.3107 nan
0.3105 0.3110 nan
0.3107 0.3103 nan
51.3 51.1 66.1
0.3234 0.3231 nan
0.3231 0.3235 nan
0.3238 0.3233 nan
0.3229 0.3241 nan
0.3243 0.3230 nan
57.4 57.2 72.3
0.3417 0.3431 nan
0.3426 0.3431 nan
0.3422 0.3437 nan
0.3430 0.3427 nan
0.3429 0.3437 nan
\end{filecontents}

\pgfplotsset{compat=1.14}
\pgfplotstableread{data.dat}\Data

\begin{document}
\newwrite\ostreama
\immediate\openout\ostreama=table1.dat
\foreach\row in {0,...,35}
{%
        \newcount\counttable
        \counttable=\row
        \divide\counttable by 6
        \multiply\counttable by 6
        \ifnum\row=\counttable
                %
        \else
                \pgfplotstablegetelem{\row}{0}\of\Data \pgfmathsetmacro\yval{\pgfplotsretval}%
                \pgfmathsetmacro\ysval{\yval ^ 2}%
                \pgfplotstablegetelem{\counttable}{0}\of\Data \pgfmathsetmacro\xval{\pgfplotsretval}%
                \immediate\write\ostreama{\xval\space\ysval}%
        \fi%
}

\begin{tikzpicture}
\begin{axis}[
    title style = {align=center},
        title = {Distance Fallen Plotted Against Time to Fall for Steel Ball},
        axis lines = left,
        xlabel = {distance in centimeters, $y$},
        ylabel = {time squared in seconds squared, $t^2$},
        domain = {20:60},
        xmin = 20, xmax = 60,
        ymin = 0.05, ymax = 0.12,
        xtick = {20, 25, 30, 35, 40, 45, 50, 55, 60},
        ytick = {0.05, 0.06, 0.07, 0.08, 0.09, 0.1, 0.11, 0.12},
        xmajorgrids = true,
        ymajorgrids = true,
        legend pos = outer north east,
]
\addplot[only marks, mark = *] file {table1.dat};
\addlegendentry{$(y, t^2)$}

\addplot+[raw gnuplot, mark = none, thick, blue] gnuplot {
        f(x)=a*x+b;
        a = 1;
    b = 1;
    set fit errorvariables;
                fit f(x) 'table1.dat' using 1:2 via a, b;
                plot [x=20:60] f(x);
        set print "pars1.dat";
        print a, a_err;
        print b, b_err;
};
\addlegendentry{\pgfplotstableread{pars1.dat}\parameters
        \pgfplotstablegetelem{0}{0}\of\parameters \pgfmathsetmacro\paramA{\pgfplotsretval}
        \pgfplotstablegetelem{1}{0}\of\parameters \pgfmathsetmacro\paramB{\pgfplotsretval}
        $\Delta t^2 = \pgfmathprintnumber{\paramA}y + \pgfmathprintnumber{\paramB}$
};
\end{axis}
\end{tikzpicture}

\end{document}

答え1

問題を発見しました。なぜエラーが発生したのかはわかりませんが、単に、再構築されたデータを保持するファイルへの書き込みに使用される書き込みストリームが閉じられていないという問題でした。その後、エラーは gnuplot に渡され、gnuplot はポイントの読み取りに失敗し、pgfplots 部分に渡され、何らかの理由で中括弧が欠落しているという形で現れました。

関連情報