전체 플롯에 걸쳐 선형 회귀 확장

전체 플롯에 걸쳐 선형 회귀 확장

데이터 세트가 있고 이에 대해 선형 회귀를 수행하고 결과 라인을 표시하려고 합니다. 계산 정밀도로 인해 값은 특정 지점 이후 정체기에 도달하므로 회귀 계산에 이러한 데이터를 포함하고 싶지 않습니다.

현재 내가 하고 있는 일은 두 개의 데이터 파일을 갖고 있는 것입니다. 하나는 모든 데이터를 담고 있고, 다른 하나는 유일한 선형 회귀에 사용되는 데이터를 담고 있습니다(최고는 아닐 수도 있지만 다른 것을 찾지 못했습니다). 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}

적합 데이터

관련 정보