请注意以下代码中的 \addlegendentry 命令。我启用它们时,它会导致我无法处理的错误。我如何正确构建此图表的图例,否则会起作用?
\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}
答案1
Missing } inserted.
尝试使用时出现错误 ( )\addlegendentry
是由于使用了选项forget plot
。此选项用于从图例中排除绘图,这与命令 相冲突\addlegendentry
。
从情节选项中删除forget plot
即可解决问题。