
Tengo una imagen tikz que contiene puntos de datos (solo se muestra una parte)
\documentclass{article}
\usepackage{pgfplots}
\newlength\figureheight
\newlength\figurewidth
\setlength{\figurewidth}{8cm}
\setlength{\figureheight}{4.5cm}
\begin{document}
\begin{tikzpicture}
\begin{axis}[%
/pgf/number format/.cd,
use comma,
1000 sep={},
width=0.951\figurewidth,
height=\figureheight,
at={(0\figurewidth,0\figureheight)},
scale only axis,
xmin=-1,
xmax=1,
xlabel style={font=\color{white!15!black}},
xlabel={xlabel},
ymin=0,
ymax=1,
ylabel style={font=\color{white!15!black}},
ylabel={ylabel},
axis background/.style={fill=white}
]
\addplot [color=black, forget plot]
table[row sep=crcr]{%
-1 0\\
-0.987 0.001\\
-0.823 0.15\\
-0.713 0.4\\
-0.684 0.5\\
-0.542 0.6\\
-0.478 0.65\\
-0.3544 0.7\\
-0.254 0.8\\
-0.14 0.9\\
0 1\\
0.057774545 0.9\\
0.15794 0.8\\
0.258105455 0.7\\
0.358270909 0.65\\
0.458436364 0.6\\
0.558601818 0.5\\
0.658767273 0.4\\
0.758932727 0.15\\
0.859098182 0.05\\
0.959263636 0.001\\
1 0\\
};
\end{axis}
\end{tikzpicture}
\end{document}
Los datos se generan a partir de mediciones y no se pueden equipar (fácilmente) con una sola función o al menos me gustaría evitar eso.
¿Existe una buena manera de animar (trazar líneas) los datos paso a paso o en fragmentos de n puntos?
Me gustaría evitar generar manualmente
Imagen-01
\addplot [color=black, forget plot]
table[row sep=crcr]{%
-1 0\\
%-0.987 0.001\\
%-0.823 0.15\\
%-0.713 0.4\\
%-0.684 0.5\\
%-0.542 0.6\\
...
};
Imagen-02
\addplot [color=black, forget plot]
table[row sep=crcr]{%
-1 0\\
-0.987 0.001\\
%-0.823 0.15\\
%-0.713 0.4\\
%-0.684 0.5\\
%-0.542 0.6\\
...
};
etc. para reproducir esas imágenes en bucle. Preferiría una solución automatizada.
Usaría la clase beamer y compilaría con XeLaTeX si esta información marca la diferencia.
Respuesta1
Una animación con beamer
herramientas integradas:
La macro de selección fue tomada prestada dehttps://tex.stackexchange.com/a/199396/36296
\documentclass{beamer}
\usepackage{pgfplots}
\newlength\figureheight
\newlength\figurewidth
\setlength{\figurewidth}{8cm}
\setlength{\figureheight}{4.5cm}
% Style to select only points from #1 to #2 (inclusive)
\pgfplotsset{select coords between index/.style 2 args={
x filter/.code={
\ifnum\coordindex<#1\def\pgfmathresult{}\fi
\ifnum\coordindex>#2\def\pgfmathresult{}\fi
}
}}
\makeatletter
\newcommand{\slide}{\the\beamer@slideinframe}
\makeatother
\begin{document}
\begin{frame}
\animate<1-22>
\transduration<1-22>{0.5}
\begin{tikzpicture}
\begin{axis}[%
/pgf/number format/.cd,
use comma,
1000 sep={},
width=0.951\figurewidth,
height=\figureheight,
at={(0\figurewidth,0\figureheight)},
scale only axis,
xmin=-1,
xmax=1,
xlabel style={font=\color{white!15!black}},
xlabel={xlabel},
ymin=0,
ymax=1,
ylabel style={font=\color{white!15!black}},
ylabel={ylabel},
axis background/.style={fill=white}
]
\addplot [color=black, forget plot,select coords between index={0}{\slide}]
table[row sep=crcr]{%
-1 0\\
-0.987 0.001\\
-0.823 0.15\\
-0.713 0.4\\
-0.684 0.5\\
-0.542 0.6\\
-0.478 0.65\\
-0.3544 0.7\\
-0.254 0.8\\
-0.14 0.9\\
0 1\\
0.057774545 0.9\\
0.15794 0.8\\
0.258105455 0.7\\
0.358270909 0.65\\
0.458436364 0.6\\
0.558601818 0.5\\
0.658767273 0.4\\
0.758932727 0.15\\
0.859098182 0.05\\
0.959263636 0.001\\
1 0\\
};
\end{axis}
\end{tikzpicture}
\pause[20]
\end{frame}
\end{document}
Respuesta2
Aquí hay una animación de algunos puntos de datos de una tabla. Para la animación utilizo elanimate
-paquete.
\documentclass{article}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usepackage{animate}
\usepackage{tikz}
\begin{filecontents}{mydata.data}
X Y
0 2
1 4
2 2
3 5
4 4
5 1
\end{filecontents}
\begin{document}
\begin{animateinline}{2}% frames per second
\multiframe{5}{ix=1+1}{% the +1 is the step size
\begin{tikzpicture}
\begin{axis}[
xlabel={X-Name},
ylabel={Y-Name},
xmin=0, xmax=5,
ymin=1, ymax=5,
]
\addplot[restrict x to domain=0:\ix,red] table [x index=0,y index=1]{mydata.data};
\end{axis}
\end{tikzpicture}
}
\end{animateinline}
\end{document}
El resultado es (vista inicial y final de la animación):
Requisitos para animar:
- pdfTEX, versión >= 1.20 o LuaTEX para salida PDF directa
- Ghostscript, versión >= 9.15 o Adobe Distiller para conversión de PS a PDF
- dvipdfmx, versión >= 20080607 para conversión de DVI a PDF
- Acrobat Reader (versión >= 7), PDF-XChange, Foxit Reader
Editar:
Para repetir las imágenes posteriormente, puede configurar la opción loop
para el animate
-paquete: \usepackage[loop]{animate}
.
Respuesta3
Dado que el OP utiliza el estándararticle
clase que no proporciona las funciones paso a paso de beamer
, este ejemplo utiliza el animate
paquete para crear el gráfico animado en una sola página de documento (usando el código de Samcarter con ligeras modificaciones):
\documentclass{article}
\usepackage{pgfplots}
\usepackage{animate}
\newlength\figureheight
\newlength\figurewidth
\setlength{\figurewidth}{8cm}
\setlength{\figureheight}{4.5cm}
% Style to select only points from #1 to #2 (inclusive)
\pgfplotsset{select coords between index/.style 2 args={
x filter/.code={
\ifnum\coordindex<#1\def\pgfmathresult{}\fi
\ifnum\coordindex>#2\def\pgfmathresult{}\fi
}
}}
\begin{document}
\begin{animateinline}[controls]{2} % 2 frames per sec
\multiframe{22}{idx=1+1}{ % 22 frames for 22 line segments
\begin{tikzpicture} % idx=1, 2, ..., 22
\begin{axis}[%
/pgf/number format/.cd,
use comma,
1000 sep={},
width=0.951\figurewidth,
height=\figureheight,
at={(0\figurewidth,0\figureheight)},
scale only axis,
xmin=-1,
xmax=1,
xlabel style={font=\color{white!15!black}},
xlabel={xlabel},
ymin=-0.1,
ymax=1,
ylabel style={font=\color{white!15!black}},
ylabel={ylabel},
axis background/.style={fill=white}
]
\addplot [
color=black, forget plot,select coords between index={0}{\idx},
unbounded coords=jump
] table[row sep=crcr]{%
-1 0\\
-0.987 0.001\\
-0.823 0.15\\
-0.713 0.4\\
-0.684 0.5\\
-0.542 0.6\\
-0.478 0.65\\
-0.3544 0.7\\
-0.254 0.8\\
-0.14 0.9\\
0 1\\
0.057774545 0.9\\
0.15794 0.8\\
0.258105455 0.7\\
0.358270909 0.65\\
0.458436364 0.6\\
0.558601818 0.5\\
0.658767273 0.4\\
0.758932727 0.15\\
0.859098182 0.05\\
0.959263636 0.001\\
1 0\\
};
\end{axis}
\end{tikzpicture}
}
\end{animateinline}
\end{document}