如何通过以下方式为 Tikz 制作动画

如何通过以下方式为 Tikz 制作动画

我希望这个 tikz 图片能够按如下方式进行动画处理:

\documentclass[border=2mm,tikz]{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.text, fit}
\usetikzlibrary{positioning,fit,backgrounds,arrows.meta}
\begin{document}
    \begin{tikzpicture}[scale=2,
        fatnode1/.style={rectangle, draw=blue, rounded corners, fill=blue!20, minimum size=0.0mm},
        fatnode2/.style={rectangle, draw=red, rounded corners, fill=red!20, minimum size=0.0mm},
        font=\sf,
        >=Latex,
        thick,
        node distance=1.2]
        \node[fatnode1] (A) at (0, 0) {Data Importation};
        \node[fatnode1, right=of A] (B) {Data Cleaning};
        \node[fatnode2, right=of B] (C) {Data Wrangling};
        \node[fatnode2, above right=of C] (D) {Data Visualization};
        \node[fatnode1, below right=of C] (E) {Data Modeling};
        \node [xshift=1.2cm, right=of C] (F) {};
        \begin{pgfonlayer}{background}
        \node [fill=blue!10, rounded corners, fit= (C) (D) (E) (F)] (H) {}; % enough to add two diagonal nodes
        \end{pgfonlayer}
        \node[fatnode2, fill=white] (I) at (H.220) {\footnotesize Data Exploration};
        \node[fatnode1, right=of H] (G) {Communicate Resuls};
        \draw [thick, ->] (A) -- (B);
        \draw [thick, ->] (B) -- (C);
        \draw [thick, ->] (H) -- (G);
        \draw [->,thick] (C) to [bend left=40]  (D);
        \draw [->,thick] (D) to [bend left=45]  (E);
        \draw [->,thick] (E) to [bend left=45]  (C);
        \node[draw, rounded corners, fit=(A) (B) (C) (D) (E) (G) (H) (I)] {};
    \end{tikzpicture}

\end{document}

我在 Tikz 中的工作流程

  • 我想Data Importation出现,然后Data Cleaning出现。

  • 我想要Circle随之旋转Data WranglingData VisualizationData Modeling

  • 我希望Communicate Result然后出现。

这个答案我对此很感兴趣,但我无法就我自己的情况弄清楚。

编辑

以下是

项目1项目2项目3项目4项目5项目6

答案1

beamer这是叠加层和包的组合animate,用于显示图示所需的步骤并使箭头动起来。动画箭头是借助decorations.markings库放置的。

tikzpicture包裹在一个命令中以接受参数(步骤 ID、箭头位置)。此外,还需要调整其大小以使其适合幻灯片beamer

在此处输入图片描述

\documentclass{beamer}

\usepackage{tikz}
\usetikzlibrary{decorations.text, decorations.markings}
\usetikzlibrary{positioning,fit,backgrounds,arrows.meta}
\usepackage{animate}

\newcommand\steppedChart[2]{%
  % #1 major steps: 0 ( ); 1 (Data Importation); 2 (Data Cleaning); 3 (Data Exploration); 4 (Communicate Results)
  % #2 arrow positions (0.0...1.0) in 3
  \resizebox{\linewidth}{!}{%
  \begin{tikzpicture}[
    fatnode1/.style={rectangle, draw=blue, rounded corners, fill=blue!20, minimum size=0.0mm},
    fatnode2/.style={rectangle, draw=red, rounded corners, fill=red!20, minimum size=0.0mm},
    font=\sf,
    >=Latex,
    thick,
    node distance=1.2]
    \ifnum#1>0
      \node[fatnode1] (A) at (0, 0) {Data Importation};
    \fi
    \ifnum#1>1
      \node[fatnode1, right=of A] (B) {Data Cleaning};
      \draw [thick, ->] (A) -- (B);
    \fi
    \ifnum#1>2
      \node[fatnode2, right=of B] (C) {Data Wrangling};
      \draw [thick, ->] (B) -- (C);
      \node[fatnode2, above right=of C] (D) {Data Visualization};
      \node[fatnode1, below right=of C] (E) {Data Modeling};
      \node [xshift=1.2cm, right=of C] (F) {};
      \begin{pgfonlayer}{background}
        \node [fill=blue!10, rounded corners, fit= (C) (D) (E) (F)] (H) {}; % enough to add two diagonal nodes
        \tikzset{decoration={markings, mark= at position #2 with {\arrow{>}}}}
        \draw [postaction={decorate},thick] (C.center) to [bend left=40]  (D.center);
        \draw [postaction={decorate},thick] (D.center) to [bend left=45]  (E.center);
        \draw [postaction={decorate},thick] (E.center) to [bend left=45]  (C.center);
      \end{pgfonlayer}
      \node[fatnode2, fill=white] (I) at (H.220) {\footnotesize Data Exploration};
    \fi  
    \ifnum#1>3
      \node[fatnode1, right=of H] (G) {Communicate Resuls};
      \draw [thick, ->] (H) -- (G);
      %%%%%  measure and save bounding box coordinates %%%%%
      \pgfpointanchor{current bounding box}{south west}\pgfgetlastxy{\llx}{\lly}
      \xdef\LL{canvas cs:x=\llx,y=\lly}
      \pgfpointanchor{current bounding box}{north east}\pgfgetlastxy{\urx}{\ury}
      \xdef\UR{canvas cs:x=\urx,y=\ury}
      %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \fi
    \coordinate (LL) at (\LL);\coordinate (UR) at (\UR); 
    \node[draw, rounded corners, fit=(LL) (UR)] {};
  \end{tikzpicture}}%
}

\begin{document}
\begin{frame}[t]{Animated Chart}
  \sbox{0}{\steppedChart{4}{0}}% measure BBOX
  \only<1>{\steppedChart{0}{0}}%
  \only<2>{\steppedChart{1}{0}}%
  \only<3>{\steppedChart{2}{0}}%
  \only<4>{%
    \begin{animateinline}[autoplay,loop]{25}%
      \multiframe{21}{r=0+0.05}{\steppedChart{3}{\r}}%
    \end{animateinline}%
  }%
  \only<5>{%
    \begin{animateinline}[autoplay,loop]{25}%
       \multiframe{21}{r=0+0.05}{\steppedChart{4}{\r}}%
    \end{animateinline}%
  }%  
\end{frame}
\end{document}

相关内容