pgfplots + animate: 複雑な行ごとのアニメーション

pgfplots + animate: 複雑な行ごとのアニメーション

80 本の対角線を持つ長方形が欲しいです:

\documentclass{article}

\usepackage{tikz}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
%------------------------
%% Options
%------------------------
    width= 100mm,
    %height = 50mm,
    xmax=70,
    xmin=0,
    ymax=50,
    ymin=0,
    axis x line=bottom,
    axis y line=left,
    enlargelimits
]
%------------------------
%% Define Clipping
%------------------------
\pgfplotsextra{%
    \clip (axis cs:0,0) rectangle (axis cs:60,40);
    % http://www.latex-community.org/forum/viewtopic.php?f=45&t=22837&start=0
}   
%------------------------    
%% Loop
%------------------------
\foreach \i in {1,2,...,80} {
\addplot[
domain=0:60,
line width=1pt,
]
  {4/6*x+40-\i}; 
}
%------------------------
%% Draw retangle
%------------------------
\draw[red,line width=2pt] (axis cs:0,0) rectangle (axis cs:60,40);  
\end{axis}     
\end{tikzpicture}

\end{document}

ここに画像の説明を入力してください

今、次のようなデータファイルがあります

4, % Line 1 is the top left corner
5,
50,
51,
52,
6,
7,
8,
9,
10,
22,
...

ここで、80 行を 1 行ずつ順番にアニメーションで表示したいとします。希望の出力を表示するために、アニメーション GIF を手動で作成しました。

ここに画像の説明を入力してください

しかし、ここから先に進むための正しいアイデアが私にはありません。

ジェイクからの解決策

回答ありがとうございます。Jake の回答は外部ファイルを使用しているため、私にとっては重要なので、これを採用します。実際の例は 1200 行を超えています。解決策は次のとおりです (Jake の回答にはファイル内容の環境がありません)。

\documentclass{article}

\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{animate}

\usepackage{filecontents}

\begin{filecontents}{index.dat}
4,
5,
50,
51,
52,
6,
7,
8,
9,
10,
22,
\end{filecontents}

\begin{document}

\pgfplotstableread[col sep=comma]{index.dat}\indextable

\begin{animateinline}[controls]{2}
\multiframe{11}{imax=0+1}{
\begin{tikzpicture}
\begin{axis}[
%------------------------
%% Options
%------------------------
    width= 100mm,
    %height = 50mm,
    xmax=70,
    xmin=0,
    ymax=50,
    ymin=0,
    axis x line=bottom,
    axis y line=left,
    enlargelimits
]
%------------------------
%% Define Clipping
%------------------------

\pgfplotsextra{%
    \clip (axis cs:0,0) rectangle (axis cs:60,40);
    % http://www.latex-community.org/forum/viewtopic.php?f=45&t=22837&start=0
}   
%------------------------    
%% Loop
%------------------------

\foreach\i in {0,...,\imax}{
\pgfplotstablegetelem{\i}{[index]0}\of{\indextable}
\edef\currentindex{\pgfplotsretval}
\addplot[
domain=0:60,
line width=1pt,
]
  {4/6*x+40-\currentindex};
}

%------------------------
%% Draw retangle
%------------------------
\draw[red,line width=2pt] (axis cs:0,0) rectangle (axis cs:60,40);  
\end{axis}     
\end{tikzpicture}}
\end{animateinline}

\end{document}

結果は次のとおりです。

ここに画像の説明を入力してください

答え1

順序付けられた値を含むデータ ファイルを PGFPlots テーブル マクロに読み込み、animateinline環境内でそれをループすることができます。

\documentclass{article}

\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{animate}

\usepackage{filecontents}


\begin{document}

\pgfplotstableread[col sep=comma]{index.dat}\indextable

\begin{animateinline}{2}
\multiframe{10}{imax=0+1}{
\begin{tikzpicture}
\begin{axis}[
%------------------------
%% Options
%------------------------
    width= 100mm,
    %height = 50mm,
    xmax=70,
    xmin=0,
    ymax=50,
    ymin=0,
    axis x line=bottom,
    axis y line=left,
    enlargelimits
]
%------------------------
%% Define Clipping
%------------------------
\pgfplotsextra{%
    \clip (axis cs:0,0) rectangle (axis cs:60,40);
    % http://www.latex-community.org/forum/viewtopic.php?f=45&t=22837&start=0
}   
%------------------------    
%% Loop
%------------------------

\foreach\i in {0,...,\imax}{
\pgfplotstablegetelem{\i}{[index]0}\of{\indextable}
\edef\currentindex{\pgfplotsretval}
\addplot[
domain=0:60,
line width=1pt,
]
  {4/6*x+40-\currentindex};
}




%------------------------
%% Draw retangle
%------------------------
\draw[red,line width=2pt] (axis cs:0,0) rectangle (axis cs:60,40);  
\end{axis}     
\end{tikzpicture}}
\end{animateinline}

\end{document}

答え2

これはビーマーで動作します。ループは外側にありますaxis

\documentclass{beamer}

\usepackage{tikz}
\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{tikzpicture}
\foreach \i [count=\j] in  {4,5,50,51,52,6,7} {
\begin{axis}[
%------------------------
%% Options
%------------------------
    width= 100mm,
    %height = 50mm,
    xmax=70,
    xmin=0,
    ymax=50,
    ymin=0,
    axis x line=bottom,
    axis y line=left,
    enlargelimits
]
%------------------------
%% Define Clipping
%------------------------
\pgfplotsextra{%
    \clip (axis cs:0,0) rectangle (axis cs:60,40);
    % http://www.latex-community.org/forum/viewtopic.php?f=45&t=22837&start=0
}   
%------------------------
%% Draw retangle
%------------------------
\draw[red,line width=2pt] (axis cs:0,0) rectangle (axis cs:60,40);  

\addplot[
domain=0:60,
line width=1pt, visible on=<\j->] 
  {4/6*x+40-\i}; 
\end{axis}}
\end{tikzpicture}
\end{frame}
\end{document}

後で GIF を作成して、さらに情報を追加します。

ここに画像の説明を入力してください ここに画像の説明を入力してください

答え3

これは、順序のリストを変更して柔軟性を高める試みです。は、2 つの引数 #1= フレーム数と #2= 線画の順序を取るコマンドです。 の #1 はリストの最後にある必要があるAppことに注意してください。\multiframe{#1}App

コマンドApp自体は、対角線以外の線を描画する whiledo ループです。

アニメーションが行われる場所を表示するには、切り取って貼り付けてください。

ここに画像の説明を入力してください

ここに画像の説明を入力してください

コード

\documentclass[border=10pt]{standalone}
\usepackage{animate}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}


\newcounter{n}
\setcounter{n}{01}
\newcommand{\App}[2]{
\whiledo{\value{n}=#1 \and \icount=#1}{
 \stepcounter{n}            % #1= # of frame
     \foreach \i in {#2} {  % #2=list
\addplot[
domain=0:60,
line width=1pt,
]
  {4/6*x+40-\i}; 
}}}


\begin{document}
%\begin{center}
\begin{animateinline}[loop,poster =first, controls]{1}
\multiframe{10}{icount=0+1}
{
\begin{tikzpicture}
\begin{axis}[
%------------------------
%% Options
%------------------------
    width= 100mm,
    %height = 50mm,
    xmax=70,
    xmin=0,
    ymax=50,
    ymin=0,
    axis x line=bottom,
    axis y line=left,
    enlargelimits
]
%------------------------
%% Define Clipping
%------------------------
\pgfplotsextra{%
    \clip (axis cs:0,0) rectangle (axis cs:60,40);
    % http://www.latex-community.org/forum/viewtopic.php?f=45&t=22837&start=0
}   
%------------------------    
%% Loop
%------------------------
\App{1}{4}
\App{2}{4,5}
\App{3}{4,5,50}
\App{4}{4,5,50,51}
\App{5}{4,5,50,51,52}
\App{6}{4,5,50,51,52,6}
\App{7}{4,5,50,51,52,6,7,8}
\App{8}{4,5,50,51,52,6,7,8,9}
\App{9}{4,5,50,51,52,6,7,8,9,10}
\App{10}{4,5,50,51,52,6,7,8,9,10,22}
%------------------------
%% Draw retangle
%------------------------
\draw[red,line width=2pt] (axis cs:0,0) rectangle (axis cs:60,40);  
\end{axis}     
\end{tikzpicture}
}
\end{animateinline}
%\end{center}
\end{document}

関連情報