I have a little Problem with a regression line I made. I need it to be from its zero up to the x-value of the highest point.
This is how it actually looks und underneath how I need it. Does anyone know how to do this?
Thank you :)
edit: of course, I already tried out domain=x1:x2
\documentclass{article}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\begin{document}
\sffamily
\pgfplotsset{every axis legend/.append style={
at={(0.03,0.97)},
anchor=north west}}
\begin{tikzpicture}
\begin{axis}[
width=10cm,
height=10cm,
x tick label style={/pgf/number format/1000 sep=},
xmin=0, xmax=0.6, ymin=0, ymax=22,
xlabel=Weg\,/\,mm,
ylabel=Kraft\,/\,N,
]
\pgfplotstableread{data.txt}
\datatable
\addplot+[
color = blue,
fill = blue,
mark = *,
mark options={solid},
only marks,
] table {
x y
0.400 18.096
0.400 18.401
0.400 17.767
0.400 16.992
0.400 16.399
0.397 15.908
0.392 15.440
0.387 14.533
0.382 13.258
0.377 11.939
};
\addlegendentry{Kraft-Weg-Kurve}
\addplot [
domain=0.25:0.4
no markers,
] table [
y={create col/linear regression={y=y}}] {
x y
0.400 18.096
0.400 18.401
0.400 17.767
0.400 16.992
0.400 16.399
0.397 15.908
0.392 15.440
0.387 14.533
0.382 13.258
0.377 11.939
};
\addlegendentry{Regression {$\pgfmathprintnumber[precision=4, fixed zerofill]{\pgfplotstableregressiona} \cdot \mathrm{t} + \pgfmathprintnumber[precision=4, fixed zerofill]{\pgfplotstableregressionb}$}}
\end{axis}
\end{tikzpicture}
\end{document}


