Legend on second frame has only one entry, labeled wrong
Using pgfplots in beamer with \only frames, the legend for the second
frame (only) inexplicably shows only one entry, with the color of the last
\addlegendentry, but the legend of the first. The other frames are fine.
(Note: my version of PGFplots is old, but when I try to update, I get an
unrelated error about a missing number treated as zero on the blank line
near the start of the file. The commit in pgfplots I used to generate
these examples is b32c2a92a257, and the next commit, 6a9ee731a433, and
evidently all newer ones, has the unrelated error.)
\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}
No comments:
Post a Comment