Bitte beachten Sie die \addlegendentry-Befehle im folgenden Code. Sobald ich sie aktiviere, tritt ein Fehler auf, den ich nicht beheben kann. Wie konstruiere ich die Legende für dieses Diagramm richtig, damit es auch sonst funktioniert?
\documentclass[]{standalone}
\usepackage{tikz, pgfplots}
\begin{document}
\definecolor{mycolor1}{rgb}{0.60000,0.20000,0.00000}%
\definecolor{mycolor2}{rgb}{0.87059,0.49020,0.00000}%
\definecolor{mycolor3}{rgb}{0.63529,0.07843,0.18431}%
\definecolor{mycolor4}{rgb}{0.74902,0.74902,0.00000}%
%
\begin{tikzpicture}
\begin{axis}[%
width=10cm,
height=8cm,
%at={(2.679444in,1.170889in)},
scale only axis,
separate axis lines,
every outer x axis line/.append style={black},
every x tick label/.append style={font=\color{black}},
xmin=5,
xmax=40,
xlabel={Variance of each entry of $\mathbf{C}_i$ in dB --------\textgreater},
xmajorgrids,
every outer y axis line/.append style={black},
every y tick label/.append style={font=\color{black}},
ymin=5,
ymax=26,
ylabel={Average Number of Users --------\textgreater},
ymajorgrids,
title={Average Number of Users v/s SINR for Different Algorithms},
legend style={legend pos=north east,draw=black,fill=white,legend cell align=left, font=\small}
]
\addplot [color=blue,solid,line width=3.0pt,mark size=7.1pt,mark=square,mark options={solid},forget plot]
table[row sep=crcr]{%
5 14.3\\
15 14.44\\
30 14.46\\
40 14.48\\
};
%\addlegendentry{N=4; L=15; Comb};
\addplot [color=red,solid,line width=3.0pt,mark size=6.7pt,mark=triangle,mark options={solid},forget plot]
table[row sep=crcr]{%
5 14.22\\
15 14.34\\
30 14.34\\
40 14.34\\
};
%\addlegendentry{N=4; L=15; EVP};
\addplot [color=mycolor1,solid,line width=3.0pt,mark size=6.7pt,mark=triangle,mark options={solid,rotate=90},forget plot]
table[row sep=crcr]{%
5 12.5\\
15 12.3\\
30 11.92\\
40 12.2\\
};
%\addlegendentry{N=4; L=15; ConRel};
\addplot [color=mycolor2,solid,line width=3.0pt,mark size=10.0pt,mark=x,mark options={solid},forget plot]
table[row sep=crcr]{%
5 22.46\\
15 22.38\\
30 23.22\\
40 22.88\\
};
%\addlegendentry{N=4; L=25; Comb};
\addplot [color=mycolor3,solid,line width=3.0pt,mark size=17.3pt,mark=diamond,mark options={solid},forget plot]
table[row sep=crcr]{%
5 21.9\\
15 21.82\\
30 22.88\\
40 22.52\\
};
%\addlegendentry{N=4; L=25; EVP};
\addplot [color=mycolor4,solid,line width=3.0pt,mark size=6.7pt,mark=triangle,mark options={solid,rotate=270},forget plot]
table[row sep=crcr]{%
5 18.8\\
15 18.36\\
30 18.54\\
40 18.82\\
};
%\addlegendentry{N=4; L=25; ConRel};
\end{axis}
\end{tikzpicture}%
\end{document}
Antwort1
Der Fehler ( Missing } inserted.
) beim Versuch der Verwendung \addlegendentry
wird durch die Verwendung der Option verursacht forget plot
. Diese Option wird verwendet, um die Diagramme aus der Legende auszuschließen, was mit dem Befehl kollidiert \addlegendentry
.
Das Entfernen forget plot
aus den Plotoptionen behebt das Problem.