Since I was asked in another post:
Trend line or line of best fit in pgfplots
to ask this question explicitly, I'm now doing so:
How can I expand the linear regression fit, generated with for example (note the semilogyaxis !!):
\documentclass[fontsize=12pt,openright,oneside,DIV11,a4paper,numbers=noenddot,headsepline,parskip=half]{scrbook}
\usepackage[latin1]{inputenc}
\usepackage[cmex10]{amsmath}
\usepackage{dsfont}
% SIUnitx package
\usepackage{siunitx}
\DeclareSIUnit{\dBm}{dBm}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\pgfplotsset{compat=1.3}
\begin{document}
\begin{tikzpicture}
\begin{semilogyaxis}[
legend style={font=\footnotesize},
legend pos=north east,
legend cell align=left,
/pgf/number format/.cd,
use comma,
xlabel=x,
ylabel=y,
ymin=,
ymax=,
xmin=0,
xmax=10,
]
\addplot+[only marks,color=black, mark=square*,mark options={fill=black}] table[x=x,y=y] {measurement1.txt};
\addlegendentry{measurement1};
% Here I would like to plot the linear regression for the whole x-axis range, not only for the x-values in measurement1.txt
\addplot+[solid,thick,color=black, no marks] table[y={create col/linear regression={y}}] {measurement1.txt};
\addlegendentry{linearregression1};
\end{semilogyaxis}
\end{tikzpicture}
\end{document}
to the full x-axis range (for example 0 to 10 and I have measurmentpoints ranging from 2 to 8 only)? It plots only for the x-values for the data points in measurement1.txt. Yes I could extract the slope and intercept using
\xdef\slope{\pgfplotstableregressiona}
\xdef\yintercept{\pgfplotstableregressionb}
\addplot+[solid,thick,color=black, no marks,domain=0:-10] (x,\slope*x+\yintercept);
but if I use semilogyaxis, the line will not be a straight line any more (of course not!). Although the linear regression generated in the axis environment is perfect linear (but is not spanned over the entire x-axis range ...).
