尽管有 NaN 数据,我如何才能使图例条目显示出来?在下面的示例中,只显示 HI 图例条目。我如何才能使 BYE 条目也显示出来?
\begin{tikzpicture}[xscale=.4, yscale=.4]
\begin{axis}[
width = 10 cm,
height = 7 cm,
label style={font=\huge},
legend style={draw={none},font=\huge},
legend entries={HI, BYE},
legend style={/tikz/every even column/.append style={column sep=0.2cm}},
legend cell align=left,
legend style={at={(0,1.2)},
anchor=north west,
legend columns=3,
cells={align=left}},]
\addplot[only marks, mark=square*, mark options={scale=1.8, fill=green}]
coordinates{
(0, 2.388854806)
};
\addplot[only marks, mark=diamond*, mark options={scale=1.8, fill=blue}]
coordinates{
(NaN,NaN) };
\end{axis}
\end{tikzpicture}
答案1
\addlegendimage{...}
您可以使用所需样式手动添加图例条目。
因此,对于您来说,下面的示例应该提供您想要的内容。
\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}[xscale=.4, yscale=.4]
\begin{axis}[
width = 10 cm,
height = 7 cm,
label style={font=\huge},
legend style={draw={none},font=\huge},
legend entries={HI, BYE},
legend style={/tikz/every even column/.append style={column sep=0.2cm}},
legend cell align=left,
legend style={at={(0,1.2)},
anchor=north west,
legend columns=3,
cells={align=left}},]
\addplot[only marks, mark=square*, mark options={scale=1.8, fill=green}]
coordinates{
(0, 2.388854806)
};
\addplot[only marks, mark=diamond*, mark options={scale=1.8, fill=blue}]
coordinates{
(NaN,NaN) };
\addlegendimage{only marks, mark=diamond*, mark options={scale=1.8, fill=blue}}
\end{axis}
\end{tikzpicture}
\end{document}