アニメーショングラフの色付け

アニメーショングラフの色付け

私はアニメーションを使用して、論文の結果を示そうとしています。そのために、MWE を構築しました。基本的に、頂点が多数あり、その塗りつぶしの色は、CSV テーブル内に記録したすべての時点のサンプル RGB 値によって指定されます。アニメーションを使用して、グラフの頂点の色の経時変化を表示したいと思います。ただし、最適な方法についてはよくわかりません。そのため、このトピックに関するご意見やご提案をお聞かせください。次のコードは、3 つの頂点を持つグラフを生成します。

\documentclass{standalone}
\usepackage{tikz,calc}

\begin{document}
   \begin{tikzpicture}[align=center,node distance=5cm]
     \tikzset{
     vertex/.style={draw,circle, line width=3pt,minimum size=1cm,text width=1cm, align=center, font=\Large},
     arc/.style={draw, line width = 3pt,-}}
     % outer shell
     \node[vertex] (V1) at (0,0) {1};
     \node[vertex] (V2) [below right of = V1] {2};
     \node[vertex] (V3) [above of = V2] {3};

     % adjacency
     \draw[arc] (V1) -- (V2);
     \draw[arc] (V3) -- (V2);
     \draw[arc] (V3) -- (V1);
   \end{tikzpicture}
\end{document}

さらに、次のエントリを含む CSV テーブルがあります。

r1,g1,b1,r2,g2,b2,r3,g3,b3
0.8147,0.1576,0.6557,0.7060,0.4387,0.2760,0.7513,0.8407,0.3517
0.9058,0.9706,0.0357,0.0318,0.3816,0.6797,0.2551,0.2543,0.8308
0.1270,0.9572,0.8491,0.2769,0.7655,0.6551,0.5060,0.8143,0.5853
0.9134,0.4854,0.9340,0.0462,0.7952,0.1626,0.6991,0.2435,0.5497
0.6324,0.8003,0.6787,0.0971,0.1869,0.1190,0.8909,0.9293,0.9172
0.0975,0.1419,0.7577,0.8235,0.4898,0.4984,0.9593,0.3500,0.2858
0.2785,0.4218,0.7431,0.6948,0.4456,0.9597,0.5472,0.1966,0.7572
0.5469,0.9157,0.3922,0.3171,0.6463,0.3404,0.1386,0.2511,0.7537
0.9575,0.7922,0.6555,0.9502,0.7094,0.5853,0.1493,0.6160,0.3804
0.9649,0.9595,0.1712,0.0344,0.7547,0.2238,0.2575,0.4733,0.5678

r1、g1、b1 はノード 1 の RGB 値です。

ご協力ありがとうございました!

編集: 可能であれば、RGB 塗りつぶしオプションを使用したいと思います。

\node[...,fill={rgb:red,4;green,2;blue,1}]

答え1

このソリューションは、LaTeX3 関数を使用してファイルから色付きの行を読み取ります。さらに、ループ\multiframebreakを途中で終了するための新しいコマンドを使用します\multiframe。( animate[ 2020/08/29])

\documentclass{standalone}

\usepackage[T1]{fontenc}
\usepackage{tikz,calc,animate}

\begin{filecontents}[overwrite,noheader]{vertexcolours.dat}
r1,g1,b1,r2,g2,b2,r3,g3,b3
0.8147,0.1576,0.6557,0.7060,0.4387,0.2760,0.7513,0.8407,0.3517
0.9058,0.9706,0.0357,0.0318,0.3816,0.6797,0.2551,0.2543,0.8308
0.1270,0.9572,0.8491,0.2769,0.7655,0.6551,0.5060,0.8143,0.5853
0.9134,0.4854,0.9340,0.0462,0.7952,0.1626,0.6991,0.2435,0.5497
0.6324,0.8003,0.6787,0.0971,0.1869,0.1190,0.8909,0.9293,0.9172
0.0975,0.1419,0.7577,0.8235,0.4898,0.4984,0.9593,0.3500,0.2858
0.2785,0.4218,0.7431,0.6948,0.4456,0.9597,0.5472,0.1966,0.7572
0.5469,0.9157,0.3922,0.3171,0.6463,0.3404,0.1386,0.2511,0.7537
0.9575,0.7922,0.6555,0.9502,0.7094,0.5853,0.1493,0.6160,0.3804
0.9649,0.9595,0.1712,0.0344,0.7547,0.2238,0.2575,0.4733,0.5678
\end{filecontents}

\usepackage{expl3}
\ExplSyntaxOn

\ior_new:N \l_colours_stream % file descriptor
\seq_new:N \g_colours_seq    % sequence var taking colours at a given time

\ior_open:Nn \l_colours_stream {vertexcolours.dat} % open file for reading
\ior_str_get:NN \l_colours_stream \l_tempa_tl % read table header and throw away

\cs_new:Npn\readColours{
  \seq_gclear:N \g_colours_seq
  \ior_str_get:NNT \l_colours_stream \l_tempa_tl{
    \seq_gset_split:NnV \g_colours_seq {,} \l_tempa_tl
  }
}

\cs_new:Npn\getColourByIndex#1{
  \seq_item:Nn \g_colours_seq {#1}
}

\ExplSyntaxOff

%\makeatletter
%\def\multiframebreak{\global\@anim@mulframecnt=1000}
%\makeatother

\begin{document}

\begin{animateinline}[controls,autoplay,loop]{1}
  \readColours%
  \multiframe{100}{}{
    \begin{tikzpicture}[align=center,node distance=5cm]
      \tikzset{
      vertex/.style={draw,fill=temp,circle, line width=3pt,minimum size=1cm,text width=1cm, align=center, font=\Large},
      arc/.style={draw, line width = 3pt,-}}
      % outer shell
      \definecolor{temp}{rgb}{\getColourByIndex{1},\getColourByIndex{2},\getColourByIndex{3}}
      \node[vertex] (V1) at (0,0) {1};
      \definecolor{temp}{rgb}{\getColourByIndex{4},\getColourByIndex{5},\getColourByIndex{6}}
      \node[vertex] (V2) [below right of = V1] {2};
      \definecolor{temp}{rgb}{\getColourByIndex{7},\getColourByIndex{8},\getColourByIndex{9}}
      \node[vertex] (V3) [above of = V2] {3};

      % adjacency
      \draw[arc] (V1) -- (V2);
      \draw[arc] (V3) -- (V2);
      \draw[arc] (V3) -- (V1);
    \end{tikzpicture}%
    \readColours%
    \ifthenelse{\equal{\getColourByIndex{1}}{}}{%
      \multiframebreak%    % no more colours -> break
    }{}%
  }  
\end{animateinline}
\end{document}

関連情報