I am working on a diagram with tikz. There are two linear regressions in the diagram, but \addlegendentry does yield weird results for the second plot. Instead of the red star (which i would have expected) the legend shows the black line from the regression.
\begin{tikzpicture}
\begin{axis}[
grid, grid style=dashed,
scale only axis,
axis y line = left,
axis x line = bottom,
ylabel = {Drehzahl $n$ in \unit{\per\minute}},
xlabel = {Ankerspannung $U_{A}$ in \unit{\volt}},
ymax = 2500,
ymin = 0,
xmin = 0,
xmax = 250,
xtick distance= 25,
ytick distance= 250,
legend pos=south east
]
\addplot[only marks,
mark=star,
blue,
] table[row sep=\\]{
X Y\\
240 1502\\
225 1402\\
207 1301\\
192 1200\\
175 1101\\
160 1000\\
145 902\\
127 799\\
112 707\\
};
\addlegendentry{Nebenschlussmaschine}
\addplot [color = black,shorten >= -0.3cm,,shorten <= -0.3cm] table[row sep=\\,
y={create col/linear regression={y=Y}}, mark=none]
{
X Y\\
240 1502\\
225 1402\\
207 1301\\
192 1200\\
175 1101\\
160 1000\\
145 902\\
127 799\\
112 707\\
};
\addplot[only marks,
mark=star,
red,
] table[row sep=\\]{
X Y\\
60 1338\\
110 2247\\
};
\addlegendentry{Reihenschlussmaschine}
\addplot [color = black,shorten >= -0.3cm,,shorten <= -0.3cm] table[row sep=\\,
y={create col/linear regression={y=Y}}, mark=none]
{
X Y\\
60 1338\\
110 2247\\
};
\end{axis}
\end{tikzpicture}
Is there some problem steming from using two regressions within one axis ? Thanks!
forget plotto the regression plot. See also https://tex.stackexchange.com/questions/14506/pgfplots-prevent-single-plot-from-being-listed-in-legend/14507#14507 – Torbjørn T. Jan 27 '22 at 21:12