我正在尝试创建一个包含多条曲线的图,因此我想使用only
beamer 的功能使每条曲线逐一出现。这是该图的 MWE,尚未尝试任何操作:
\documentclass[xcolor=dvipsnames, fleqn]{beamer}
\setbeamercovered{invisible}
\beamertemplatenavigationsymbolsempty
\usepackage{tikz}
\usepackage{pgfplots}
\usepgfplotslibrary{colorbrewer}
\usetikzlibrary{plotmarks, calc, spy, pgfplots.polar, shapes.geometric, external}
\tikzexternalize[prefix=./figures/tikz/]
\begin{document}
\begin{frame}[fragile]
\begin{figure}
\begin{tikzpicture}
\begin{loglogaxis}[legend style={fill=none, at={(0,1.)}, anchor=north west, draw=none}]
\addplot + [thick, mark=none] table[] {
1 2.00
3 25.49
7 100.67
};
\addplot + [thick, dashed, mark=none] table[] {
1 2.74
3 12.74
7 33.43
};
\addplot + [thick, mark=none] table[] {
1 11.75
3 46.66
7 424.49
};
\legend{ curve 1 \\ curve 2 \\ curve 3 \\}
\end{loglogaxis}
\end{tikzpicture}
\end{figure}
\end{frame}
\end{document}
我需要,external
因为实际的演示中有很多这样的曲线。现在看来,让每条曲线出现就像用 封闭每条曲线一样简单only<1->
,正如我根据上一个答案发现的那样找到这里,但事实并非如此。似乎与only
不太好,所以我尝试在框架前后external
添加\tikzexternaldisable
和:\tikzexternalenable
\documentclass[xcolor=dvipsnames, fleqn]{beamer}
\setbeamercovered{invisible}
\beamertemplatenavigationsymbolsempty
\usepackage{tikz}
\usepackage{pgfplots}
\usepgfplotslibrary{colorbrewer}
\usetikzlibrary{plotmarks, calc, spy, pgfplots.polar, shapes.geometric, external}
\tikzexternalize[prefix=./figures/tikz/]
\tikzexternaldisable
\begin{document}
\begin{frame}[fragile]
\begin{figure}
\begin{tikzpicture}
\begin{loglogaxis}[legend style={fill=none, at={(0,1.)}, anchor=north west, draw=none}]
\only<1->{%
\addplot + [thick, mark=none] table[] {
1 2.00
3 25.49
7 100.67
};
}%
\only<2>{%
\addplot + [thick, dashed, mark=none] table[] {
1 2.74
3 12.74
7 33.43
};
}%
\only<3>{%
\addplot + [thick, mark=none] table[] {
1 11.75
3 46.66
7 424.49
};
}%
\end{loglogaxis}
\end{tikzpicture}
\end{figure}
\end{frame}
\tikzexternalenable
\end{document}
我甚至删除了图例,但这仍然不起作用,并给了我Package pgfplots Error: Could not read table file '" 1 2.00 3 25.49 7 100.67 "'
然后我决定尝试真正的答案在同一篇文章中,使用visible on
。这与外部配合不好,但这次它有点用当我禁用外部时:
\documentclass[xcolor=dvipsnames, fleqn]{beamer}
\setbeamercovered{invisible}
\beamertemplatenavigationsymbolsempty
\usepackage{tikz}
\usepackage{pgfplots}
\usepgfplotslibrary{colorbrewer}
\usetikzlibrary{plotmarks, calc, spy, pgfplots.polar, shapes.geometric, external}
\tikzexternalize[prefix=./figures/tikz/]
\tikzset{
invisible/.style={opacity=0},
visible on/.style={alt={#1{}{invisible}}},
alt/.code args={<#1>#2#3}{%
\alt<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}} % \pgfkeysalso doesn't change the path
},
}
\tikzexternaldisable
\begin{document}
\begin{frame}[fragile]
\begin{figure}
\begin{tikzpicture}
\begin{loglogaxis}[legend style={fill=none, at={(0,1.)}, anchor=north west, draw=none}]
\addplot + [thick, mark=none, visible on=<1->] table[] {
1 2.00
3 25.49
7 100.67
};
\addplot + [thick, dashed, mark=none, visible on=<2->] table[] {
1 2.74
3 12.74
7 33.43
};
\addplot + [thick, mark=none, visible on=<3->] table[] {
1 11.75
3 46.66
7 424.49
};
\legend{ curve 1 \\ curve 2 \\ curve 3 \\}
\end{loglogaxis}
\end{tikzpicture}
\end{figure}
\end{frame}
\tikzexternalenable
\end{document}
我希望每个图例都带有相应的曲线。在这个阶段,我放弃了,因为我无法弄清楚如何做看似如此简单的事情。
更新
我使用以下方法部分解决了图例问题\addlegendentry[visible on=<1->]
:
\documentclass[xcolor=dvipsnames, fleqn]{beamer}
\setbeamercovered{invisible}
\beamertemplatenavigationsymbolsempty
\usepackage{tikz}
\usepackage{pgfplots}
\usepgfplotslibrary{colorbrewer}
\usetikzlibrary{plotmarks, calc, spy, pgfplots.polar, shapes.geometric, external}
\tikzexternalize[prefix=./figures/tikz/]
\tikzset{
invisible/.style={opacity=0},
visible on/.style={alt={#1{}{invisible}}},
alt/.code args={<#1>#2#3}{%
\alt<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}} % \pgfkeysalso doesn't change the path
},
}
\tikzexternaldisable
\begin{document}
\begin{frame}[fragile]
\begin{figure}
\begin{tikzpicture}
\begin{loglogaxis}[legend style={fill=none, at={(0,1.)}, anchor=north west, draw=none}]
\addplot + [thick, mark=none, visible on=<1->] table[] {
1 2.00
3 25.49
7 100.67
};
\addlegendentry[visible on=<1->]{curve 1}
\addplot + [thick, dashed, mark=none, visible on=<2>] table[] {
1 2.74
3 12.74
7 33.43
};
\addlegendentry[visible on=<2>]{curve 2}
\addplot + [thick, mark=none, visible on=<3>] table[] {
1 11.75
3 46.66
7 424.49
};
\addlegendentry[visible on=<3>]{curve 3}
\end{loglogaxis}
\end{tikzpicture}
\end{figure}
\end{frame}
\tikzexternalenable
\end{document}
但是,如果我现在隐藏第二个情节,第三个图例就不在正确的位置了:
答案1
@aaagon 的格式更好:
定义图例时可以使用:
\legend{ \only<1->{曲线 1} \\ \only<2->{曲线 2} \\ \only<3->{曲线 3} \\ };
使用 \only{} 命令不能保证曲线和标签曲线同时出现。