pgfplots + animate: animación complicada línea por línea

pgfplots + animate: animación complicada línea por línea

Quiero un rectángulo con 80 líneas diagonales:

\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}

ingrese la descripción de la imagen aquí

Ahora tengo un archivo de datos que se parece

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

Ahora quiero que las 80 líneas aparezcan en una animación animada en ese orden línea por línea. Hice un gif animado manualmente para mostrar el resultado deseado:

ingrese la descripción de la imagen aquí

Pero a partir de aquí no tengo la idea correcta para proceder.

Solución de Jake

¡Gracias por las respuestas! Acepto la respuesta de Jake porque utiliza un archivo externo que es importante para mí. Mi ejemplo real tiene más de 1200 líneas. Aquí está la solución (a la respuesta de Jake le falta el entorno de contenido del archivo):

\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}

Aquí está el resultado:

ingrese la descripción de la imagen aquí

Respuesta1

Puede leer el archivo de datos que contiene los valores ordenados en una macro de tabla PGFPlots y luego recorrerlo dentro del animateinlineentorno:

\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}

Respuesta2

Esto funciona con proyector. El circuito está afuera 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}

Luego haré un gif y agregaré más información.

ingrese la descripción de la imagen aquí ingrese la descripción de la imagen aquí

Respuesta3

Este es un intento en el que la lista de pedidos se puede cambiar para mayor flexibilidad. Appes un comando que toma dos argumentos #1= # de fotogramas y #2= el orden del dibujo lineal. Tenga en cuenta que el número 1 \multiframe{#1}debe ser el último de la Applista.

El Appcomando en sí es un bucle whiledo que dibuja líneas fuera de la diagonal.

Corte y pegue para mostrar cómo se desarrolla la animación.

ingrese la descripción de la imagen aquí

ingrese la descripción de la imagen aquí

Código

\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}

información relacionada