データセットがあり、それらに対して線形回帰を実行し、結果の線を表示したいと考えています。計算精度により、値は特定のポイント以降で安定するため、これらのデータを回帰の計算に含めたくありません。
私が現在行っているのは、2 つのデータ ファイルを用意することです。1 つはすべてのデータを含み、もう 1 つは単独の線形回帰に使用されるデータを含みます (最適ではないかもしれませんが、他に何も見つかりませんでした)。これが MWE です。
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepackage{pgfplotstable}
\begin{filecontents}[overwrite,noheader]{data.dat}
h err
0.05 3.11604689111e-09
0.025 1.89857594659e-11
0.0125 3.14299545014e-13
0.00625 2.38864314351e-14
0.003125 4.93001614302e-14
\end{filecontents}
\begin{filecontents}[overwrite,noheader]{data_for_reg.dat}
h err
0.05 3.11604689111e-09
0.025 1.89857594659e-11
0.0125 3.14299545014e-13
\end{filecontents}
\begin{document}
\begin{tikzpicture}
\begin{axis}[xmode=log, ymode=log]
\addplot[only marks,blue] table[x=h,y=err]{data.dat};
\addplot[no markers,red,thick] table [x=h,y={create col/linear regression={y=err}}] {data_for_reg.dat};
\end{axis}
\end{tikzpicture}
\end{document}
結果として、すべてのデータ (青) と、選択されたポイントのみの線形回帰 (赤) を含む図が生成されます。
私がやりたいのは、上の図で緑色で表示されているように、この線をプロット全体に拡張することです(緑色はスクリーンショットに手動で追加されています)。
答え1
マニュアルよりpgfplots
(セクション4.24フィッティングライン – 回帰) の場合、回帰のパラメータは、\pgfplotstableregressiona
およびに格納されます\pgfplotstableregressionb
。したがって、適切なドメインとキーを使用して、update limits=false
軸を変更せずに、対応する関数を描画します。
\addplot[update limits=false, no markers, green, thick, domain={1e-3:1e-1}]
{x^\pgfplotstableregressiona*exp(\pgfplotstableregressionb)};
例:
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepackage{pgfplotstable}
\begin{filecontents}[overwrite,noheader]{data.dat}
h err
0.05 3.11604689111e-09
0.025 1.89857594659e-11
0.0125 3.14299545014e-13
0.00625 2.38864314351e-14
0.003125 4.93001614302e-14
\end{filecontents}
\begin{filecontents}[overwrite,noheader]{data_for_reg.dat}
h err
0.05 3.11604689111e-09
0.025 1.89857594659e-11
0.0125 3.14299545014e-13
\end{filecontents}
\begin{document}
\begin{tikzpicture}
\begin{axis}[xmode=log, ymode=log]
\addplot[only marks,blue] table[x=h,y=err]{data.dat};
\addplot+[no markers, white] table [x=h,y={create col/linear regression={y=err}}] {data_for_reg.dat};
\addplot[update limits=false, no markers, green, thick, domain={1e-3:1e-1}]
{x^\pgfplotstableregressiona*exp(\pgfplotstableregressionb)};
\end{axis}
\end{tikzpicture}
\end{document}