Tenga en cuenta los comandos \addlegendentry en el siguiente código. En el momento en que los habilito, aparece un error que no puedo manejar. ¿Cómo construyo correctamente la leyenda de este gráfico que funciona de otra manera?
\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}
Respuesta1
El error ( Missing } inserted.
) al intentar usar \addlegendentry
es causado por el uso de la opción forget plot
. Esta opción se utiliza para excluir los gráficos de la leyenda, lo que choca con el comando \addlegendentry
.
Eliminar forget plot
de las opciones de la trama soluciona el problema.