![Example: Linear Regression with pgfplots](https://writelatex.s3.amazonaws.com/published_ver/23.jpeg?X-Amz-Expires=14400&X-Amz-Date=20240701T021837Z&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAWJBOALPNFPV7PVH5/20240701/us-east-1/s3/aws4_request&X-Amz-SignedHeaders=host&X-Amz-Signature=24e713c2cf0be794082b97fb8861344fca1a8993ab3f37dccb65911212745750)
Example: Linear Regression with pgfplots
Last Updated
11年前
License
Other (as stated in the work)
Abstract
Example: Linear Regression with pgfplots
![Example: Linear Regression with pgfplots](https://writelatex.s3.amazonaws.com/published_ver/23.jpeg?X-Amz-Expires=14400&X-Amz-Date=20240701T021837Z&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAWJBOALPNFPV7PVH5/20240701/us-east-1/s3/aws4_request&X-Amz-SignedHeaders=host&X-Amz-Signature=24e713c2cf0be794082b97fb8861344fca1a8993ab3f37dccb65911212745750)
% from http://tex.stackexchange.com/questions/117409/linear-regression-trend-line-with-pgfplots
\documentclass{standalone}
\usepackage{siunitx}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\title{Example: Linear Regression with pgfplots}
\begin{document}
\begin{tikzpicture}
\pgfplotsset{width=10cm,
compat=1.3,
legend style={font=\footnotesize}}
\begin{axis}[
xlabel={Glukosekonzentration [\si{\gram\per\liter}]},
ylabel={Absorption $[-]$},
legend cell align=left,
legend pos=north west]
\addplot[only marks] table[row sep=\\]{
X Y\\
0.1 0.147\\
0.1 0.165\\
0.8 0.918\\
0.8 1.149\\
};
\addlegendentry{Messpunkte}
\addplot table[row sep=\\,
y={create col/linear regression={y=Y}}] % compute a linear regression from the
%input table
{
X Y\\
0.1 0.147\\
0.1 0.165\\
0.8 0.918\\
0.8 1.149\\
};
\addlegendentry{%
$\pgfmathprintnumber{\pgfplotstableregressiona} \cdot x
\pgfmathprintnumber[print sign]{\pgfplotstableregressionb}$ lin. Regression} %
\end{axis}
\end{tikzpicture}
\end{document}