![Example: Linear Regression with pgfplots](https://writelatex.s3.amazonaws.com/published_ver/23.jpeg?X-Amz-Expires=14400&X-Amz-Date=20240701T021759Z&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAWJBOALPNFPV7PVH5/20240701/us-east-1/s3/aws4_request&X-Amz-SignedHeaders=host&X-Amz-Signature=f260984534afa92baa03b0210a61df52715dfdd50cccd149d42bc9d0c17ee090)
Example: Linear Regression with pgfplots
Last Updated
för 11 år sedan
Licens
Other (as stated in the work)
Sammanfattning
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=20240701T021759Z&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAWJBOALPNFPV7PVH5/20240701/us-east-1/s3/aws4_request&X-Amz-SignedHeaders=host&X-Amz-Signature=f260984534afa92baa03b0210a61df52715dfdd50cccd149d42bc9d0c17ee090)
% 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}