我正在创建一个逐步展示视觉元素的pgfplot
界面。特别是,我添加了额外的刻度标记,这些标记出现在后面的帧中,使用描述的样式beamer
visible on
这里。
我也有与轴相交的 TikZ 形状,我希望它们显示在轴下方。我尝试使用 选项set layers
,pgfplots
但这似乎破坏了上述刻度标记的显示 - 它们只出现在第一帧,而不是后续帧。我如何确保两者:
- 第一帧上不会出现额外的刻度标记;并且
- 环境内部绘制的形状
axis
被放置在轴下方?
以下是 MWE:
\documentclass{beamer}
\usepackage{pgfplots}
\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
},
}
\begin{document}
\begin{frame}
\begin{center}
\begin{tikzpicture}
\begin{axis}[
clip=false,xtick={0,1},
extra x ticks={0.5},extra x tick style={visible on=<2->,grid=none},
extra x tick labels={to appear later},
xmin=-0.05,xmax=1.05,ymin=0,
axis line style=semithick,
% set layers=axis on top % Uncommenting this ruins the reveal
]
\addplot[domain=0:1,samples=300,visible on=<2->,color=blue,line width=1pt]{0.3-0.1*x} node(endofplot)[anchor=west]{$f$};
\draw[fill=blue!50!white,opacity=0.95] (axis cs:0.3,-0.05) rectangle (axis cs:0.6,0.1) {};
\end{axis}
\end{tikzpicture}
\end{center}
\end{frame}
\end{document}
答案1
我并不完全确定,但我认为这是你所需要的:
\documentclass{beamer}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\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
},
}
\begin{document}
\begin{frame}
\begin{tikzpicture}
\begin{axis}[
% set layers=true,
axis on top=true,
clip=false,
xtick={0,1},
extra x ticks={0.5},
extra x tick style={visible on=<2>},
extra x tick labels={to appear later},
xmin=-0.05,
xmax=1.05,
ymin=0,
ymax=0.3,
axis line style=semithick,
]
\only<1->{\draw[fill=blue!50!white,opacity=0.95] (axis cs:0.3,-0.05) rectangle (axis cs:0.6,0.1) {};}
\only<2->{\addplot[domain=0:1,samples=300,visible on=<2->,color=blue,line width=1pt]{0.3-0.1*x} node(endofplot)[anchor=west]{$f$};}
\end{axis}
\end{tikzpicture}
\end{frame}
\end{document}