4

im having problems with the linear regression function in PGFplots. My results with this plot are way to steep. The table is in an extern file, i put it in with the first plot, so you can see my data.

\documentclass[12pt]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}
\usepackage[babel,german=guillemets]{csquotes}
\usepackage[backend=biber]{biblatex}
\usepackage{pgfplots,tikz}
\pgfplotsset{compat=1.12}
\usepackage{pgfplotstable}
\begin{document}
\begin{figure}[htbp]
    \label{pic:cmn25}
    \begin{center}
    \begin{tikzpicture}
    \begin{axis}
    [
        width=14cm,
        xlabel={$c_A^2 [-]$},
        ylabel={$c_W [-]$},
        ymin=0.1, ymax=0.25,
        xmin=-0.1, xmax=1.3,
        legend pos=north west,
        legend entries={mit HLW,
                        ohne HLW,
                        lin. mit HLW,
                        lin. ohne HLW},
    ]
    \addplot table[x={cA2_mit},y={cW_mit}]
    {
    cW_mit  cA2_mit cW_ohne cA2_ohne
0.119   0.008   0.113   0.000
0.116   0.042   0.111   0.031
0.117   0.162   0.111   0.111
0.123   0.346   0.117   0.240
0.137   0.570   0.125   0.394
0.155   0.796   0.140   0.555
0.177   1.001   0.157   0.679
0.201   1.185   0.178   0.796
    };
    \addplot table[x={cA2_ohne},y={cW_ohne}]
    {
    cW_mit  cA2_mit cW_ohne cA2_ohne
0.119   0.008   0.113   0.000
0.116   0.042   0.111   0.031
0.117   0.162   0.111   0.111
0.123   0.346   0.117   0.240
0.137   0.570   0.125   0.394
0.155   0.796   0.140   0.555
0.177   1.001   0.157   0.679
0.201   1.185   0.178   0.796
    };
    \addplot [thick, blue] table[y={create col/linear regression={y=cW_mit}}]
    {
    cW_mit  cA2_mit cW_ohne cA2_ohne
0.119   0.008   0.113   0.000
0.116   0.042   0.111   0.031
0.117   0.162   0.111   0.111
0.123   0.346   0.117   0.240
0.137   0.570   0.125   0.394
0.155   0.796   0.140   0.555
0.177   1.001   0.157   0.679
0.201   1.185   0.178   0.796
    };
    \addplot [thick, red] table[y={create col/linear regression={y=cW_ohne}}]
    {
    cW_mit  cA2_mit cW_ohne cA2_ohne
0.119   0.008   0.113   0.000
0.116   0.042   0.111   0.031
0.117   0.162   0.111   0.111
0.123   0.346   0.117   0.240
0.137   0.570   0.125   0.394
0.155   0.796   0.140   0.555
0.177   1.001   0.157   0.679
0.201   1.185   0.178   0.796
    };
    \end{axis}
    \end{tikzpicture}
    \caption{$c_{mN25}$ über $\alpha$}
    \end{center}
\end{figure}
\end{document}

My results look like this:

Results

They should look like this though (done with excel)

enter image description here

1 Answer 1

2

Found the solution. In the Line:

\addplot [thick, red] table[y={create col/linear regression={y=cW_ohne}}]

I have to add a column for the x-values:

\addplot [thick, red] table[**x={cA2_ohne}**,y={create col/linear regression={y=cW_ohne}}]

I wonder why though, I didn't have to do it in another diagram. Oh well, I hope this helps someone.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .