Beamer:使用“pgfplots”覆盖从表中读取数据

Beamer:使用“pgfplots”覆盖从表中读取数据

我想通过包pgfplots仅在帧的后续幻灯片上显示图表。但是在图表上使用\uncover\visible会产生错误:Package pgfplots Error: Could not read table file '" {Other Categories} 0 0 . }使用下面的 MWE。

如果我删除\uncover,文件将编译并生成静态帧,如下所示。

如何才能仅在某些幻灯片上显示图表?

梅威瑟:

\documentclass{beamer}

\setbeamercovered{dynamic}

\usepackage{tikz}

\usepackage{pgfplots}
\pgfplotsset{compat=1.16}

\begin{document}

\begin{frame}[fragile]
    \uncover<2->{
        \begin{figure}
            \caption{A Stacked Bar Chart}
            \smallskip
            {\centering
                \begin{tikzpicture}[scale=0.7]
                    \begin{axis}[
                    ybar stacked,
                    xlabel={Category},
                    ylabel={Quantity},
                    ymin=0,
                    symbolic x coords={A,B/C,D,Other Categories},
                    xtick=data,
                    legend style={
                        at={(0.5,-0.3)},
                        anchor=north,
                    },
                    axis lines=left,
                    enlarge x limits=true,
                    enlarge y limits={true,upper},
                    ]
                    \addplot[fill=white] table [header=false,x index = {0}, y index = {1}] {
                        {Other Categories} 24.4417   18.9708   28.7252   28.7150
                        A                  27.1738    2.9262   28.9467   14.5613
                        B/C                 3.8096    8.3549    4.7284   24.0084
                        D                  27.4013   16.4064   29.1178    4.2566
                    };
                    \addplot[fill=red] table [header=false,x index = {0}, y index = {1}] {
                        {Other Categories}      0         0       .           .
                        A                  8.4352   19.1898       .           .
                        B/C               18.3147   13.1148       .           .
                        D                 15.8441    0.7142       .           .
                    };
                    \legend{White part, Red part}
                    \end{axis}
                \end{tikzpicture}
            \par}
        \end{figure}
    }   
\end{frame}

\end{document}

静态框架: 静态帧

答案1

是的,运行调查阶段,与构建框架的pgfplots方式相冲突。好消息是,有一个 TibeamerZ 库用于这些目的,overlay-beamer-styles它允许您实现我认为您想要的东西。

\documentclass{beamer}

\setbeamercovered{dynamic}

\usepackage{tikz}
\usetikzlibrary{overlay-beamer-styles}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}

\begin{document}

\begin{frame}[fragile]
\frametitle{Variant A: picture completely invisible on frame 1}    
        \begin{figure}
            \uncover<2->{\caption{A Stacked Bar Chart}}
            \smallskip
            {\centering
                \begin{tikzpicture}[scale=0.7,visible on=<2>]
                    \begin{axis}[
                    ybar stacked,
                    xlabel={Category},
                    ylabel={Quantity},
                    ymin=0,
                    symbolic x coords={A,B/C,D,Other Categories},
                    xtick=data,
                    legend style={
                        at={(0.5,-0.3)},
                        anchor=north,
                    },
                    axis lines=left,
                    enlarge x limits=true,
                    enlarge y limits={true,upper},
                    ]
                    \addplot[fill=white] table [header=false,x index = {0}, y index = {1}] {
                        {Other Categories} 24.4417   18.9708   28.7252   28.7150
                        A                  27.1738    2.9262   28.9467   14.5613
                        B/C                 3.8096    8.3549    4.7284   24.0084
                        D                  27.4013   16.4064   29.1178    4.2566
                    };
                    \addplot[fill=red] table [header=false,x index = {0}, y index = {1}] {
                        {Other Categories}      0         0       .           .
                        A                  8.4352   19.1898       .           .
                        B/C               18.3147   13.1148       .           .
                        D                 15.8441    0.7142       .           .
                    };
                    \legend{White part, Red part}
                    \end{axis}
                \end{tikzpicture}}
            \par
        \end{figure}
\end{frame}


\begin{frame}[fragile]
\frametitle{Variant B: picture transparent on frame 1}   
        \begin{figure}
            \uncover<2->{\caption{A Stacked Bar Chart}}
            \smallskip
            {\centering
                \begin{tikzpicture}[scale=0.7,alt=<1>{opacity=0.1}]
                    \begin{axis}[
                    ybar stacked,
                    xlabel={Category},
                    ylabel={Quantity},
                    ymin=0,
                    symbolic x coords={A,B/C,D,Other Categories},
                    xtick=data,
                    legend style={
                        at={(0.5,-0.3)},
                        anchor=north,
                    },
                    axis lines=left,
                    enlarge x limits=true,
                    enlarge y limits={true,upper},
                    ]
                    \addplot[fill=white] table [header=false,x index = {0}, y index = {1}] {
                        {Other Categories} 24.4417   18.9708   28.7252   28.7150
                        A                  27.1738    2.9262   28.9467   14.5613
                        B/C                 3.8096    8.3549    4.7284   24.0084
                        D                  27.4013   16.4064   29.1178    4.2566
                    };
                    \addplot[fill=red] table [header=false,x index = {0}, y index = {1}] {
                        {Other Categories}      0         0       .           .
                        A                  8.4352   19.1898       .           .
                        B/C               18.3147   13.1148       .           .
                        D                 15.8441    0.7142       .           .
                    };
                    \legend{White part, Red part}
                    \end{axis}
                \end{tikzpicture}}
            \par
        \end{figure}
\end{frame}

\end{document}

在此处输入图片描述

相关内容