![第二帧上的图例只有一个条目,标记错误](https://linux22.com/image/273329/%E7%AC%AC%E4%BA%8C%E5%B8%A7%E4%B8%8A%E7%9A%84%E5%9B%BE%E4%BE%8B%E5%8F%AA%E6%9C%89%E4%B8%80%E4%B8%AA%E6%9D%A1%E7%9B%AE%EF%BC%8C%E6%A0%87%E8%AE%B0%E9%94%99%E8%AF%AF.png)
在带有框架的 beamer 中使用 pgfplots \only
,第二帧 (仅) 的图例莫名其妙地只显示一个条目,颜色与最后一个相同\addlegendentry
,但图例与第一个相同。其他帧都很好。
(注意:我的 PGFplots 版本较旧,但是当我尝试更新时,我收到一个不相关的错误,关于在文件开头附近的空白行上缺少一个被视为零的数字。我在 pgfplots 中用来生成这些示例的提交是 b32c2a92a257,下一个提交 6a9ee731a433,显然所有较新的提交,都有不相关的错误。)
\documentclass{beamer}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{frame}{Pgfplots problem with legend on second frame}
\begin{center}
\begin{tikzpicture}
%%\pgfplotsset{every axis legend/.append style={at={(1.02,1.0)}, anchor=north west}}
\begin{axis}[ xlabel={x}, ylabel={y},
xmin=-1, xmax=1, ymin=0, ymax=2, width=8cm]
\only<1>{
\addplot[color=green,very thick,mark=none] coordinates {
(-1.0000, 0.2072) (-0.9900, 0.2550) (-0.9800, 0.3108) (-0.9700, 0.3751) (-0.9600, 0.4480)
( 0.9500, 0.0631) ( 0.9600, 0.0816) ( 0.9700, 0.1046) ( 0.9800, 0.1327) ( 0.9900, 0.1666)
};
\addlegendentry{green}
\addplot[color=blue,very thick,mark=none] coordinates {
(-1.0000, 0.8885) (-0.9900, 0.8380) (-0.9800, 0.7513) (-0.9700, 0.6403) (-0.9600, 0.5188)
( 0.9500, 0.0003) ( 0.9600, 0.0001) ( 0.9700, 0.0000) ( 0.9800, 0.0000) ( 0.9900, 0.0000)
};
\addlegendentry{blue}
\addplot[color=red,very thick,mark=none] coordinates {
(-1.0000, 0.1841) (-0.9900, 0.2137) (-0.9800, 0.2335) (-0.9700, 0.2402) (-0.9600, 0.2325)
( 0.9500, 0.0000) ( 0.9600, 0.0000) ( 0.9700, 0.0000) ( 0.9800, 0.0000) ( 0.9900, 0.0000)
};
\addlegendentry{red}
}
\only<2>{
\addplot[color=green,very thick,mark=none, forget plot] coordinates {
(-1.0000, 0.0011) (-0.9900, 0.0017) (-0.9800, 0.0024) (-0.9700, 0.0035) (-0.9600, 0.0049)
( 0.9500, 0.0001) ( 0.9600, 0.0002) ( 0.9700, 0.0003) ( 0.9800, 0.0005) ( 0.9900, 0.0008)
};
\addlegendentry{green}
\addplot[color=blue,very thick,mark=none, forget plot] coordinates {
(-1.0000, 0.4644) (-0.9900, 0.3446) (-0.9800, 0.2430) (-0.9700, 0.1630) (-0.9600, 0.1039)
( 0.9500, 0.0000) ( 0.9600, 0.0000) ( 0.9700, 0.0000) ( 0.9800, 0.0001) ( 0.9900, 0.0003)
};
\addlegendentry{blue}
\addplot[color=red,very thick,mark=none] coordinates {
(-1.0000, 0.0005) (-0.9900, 0.0006) (-0.9800, 0.0006) (-0.9700, 0.0006) (-0.9600, 0.0005)
( 0.9500, 0.0000) ( 0.9600, 0.0000) ( 0.9700, 0.0000) ( 0.9800, 0.0000) ( 0.9900, 0.0000)
};
\addlegendentry{red}
}
\only<3>{
\addplot[color=green,very thick,mark=none] coordinates {
(-1.0000, 0.0099) (-0.9900, 0.0136) (-0.9800, 0.0186) (-0.9700, 0.0251) (-0.9600, 0.0336)
( 0.9500, 0.0017) ( 0.9600, 0.0025) ( 0.9700, 0.0036) ( 0.9800, 0.0050) ( 0.9900, 0.0071)
};
\addlegendentry{green}
\addplot[color=blue,very thick,mark=none] coordinates {
(-1.0000, 0.1346) (-0.9900, 0.0837) (-0.9800, 0.0495) (-0.9700, 0.0278) (-0.9600, 0.0149)
( 0.9500, 0.0002) ( 0.9600, 0.0005) ( 0.9700, 0.0012) ( 0.9800, 0.0026) ( 0.9900, 0.0054)
};
\addlegendentry{blue}
\addplot[color=red,very thick,mark=none] coordinates {
(-1.0000, 0.0013) (-0.9900, 0.0011) (-0.9800, 0.0009) (-0.9700, 0.0007) (-0.9600, 0.0005)
( 0.9500, 0.0000) ( 0.9600, 0.0000) ( 0.9700, 0.0000) ( 0.9800, 0.0000) ( 0.9900, 0.0000)
};
\addlegendentry{red}
}
\only<4>{
\addplot[color=green,very thick,mark=none] coordinates {
(-1.0000, 0.0131) (-0.9900, 0.0179) (-0.9800, 0.0243) (-0.9700, 0.0325) (-0.9600, 0.0431)
( 0.9500, 0.0024) ( 0.9600, 0.0034) ( 0.9700, 0.0049) ( 0.9800, 0.0068) ( 0.9900, 0.0095)
};
\addlegendentry{green}
\addplot[color=blue,very thick,mark=none] coordinates {
(-1.0000, 0.2304) (-0.9900, 0.1530) (-0.9800, 0.0966) (-0.9700, 0.0580) (-0.9600, 0.0331)
( 0.9500, 0.0001) ( 0.9600, 0.0001) ( 0.9700, 0.0004) ( 0.9800, 0.0009) ( 0.9900, 0.0020)
};
\addlegendentry{blue}
\addplot[color=red,very thick,mark=none] coordinates {
(-1.0000, 0.0030) (-0.9900, 0.0027) (-0.9800, 0.0023) (-0.9700, 0.0019) (-0.9600, 0.0014)
( 0.9500, 0.0000) ( 0.9600, 0.0000) ( 0.9700, 0.0000) ( 0.9800, 0.0000) ( 0.9900, 0.0000)
};
\addlegendentry{red}
}
\end{axis}
\end{tikzpicture}
\end{center}
\end{frame}
\end{document}
答案1
您需要forget plot
从第二帧中的两个图中删除键。forget plot
导致图不显示在图例中。