
Ich möchte ein Rechteck mit 80 Diagonalen:
\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}
Jetzt habe ich eine Datendatei, die so aussieht
4, % Line 1 is the top left corner
5,
50,
51,
52,
6,
7,
8,
9,
10,
22,
...
Nun möchte ich, dass die 80 Zeilen in einer animierten Animation in dieser Reihenfolge Zeile für Zeile erscheinen. Ich habe manuell ein animiertes GIF erstellt, um die gewünschte Ausgabe anzuzeigen:
Aber von hier aus habe ich nicht die richtige Idee, wie ich weiter vorgehen soll.
Lösung von Jake
Danke für die Antworten! Ich akzeptiere Jakes Antwort, da sie eine externe Datei verwendet, was für mich wichtig ist. Mein echtes Beispiel hatte über 1200 Zeilen. Hier ist die Lösung (in Jakes Antwort fehlt die Dateiinhaltsumgebung):
\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}
Hier ist das Ergebnis:
Antwort1
Sie können die Datendatei mit den geordneten Werten in ein PGFPlots-Tabellenmakro einlesen und diese dann innerhalb der animateinline
Umgebung durchlaufen:
\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}
Antwort2
Das funktioniert mit Beamer. Die Schleife ist außen 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}
Später werde ich ein GIF erstellen und weitere Informationen hinzufügen.
Antwort3
Dies ist ein Versuch, die Reihenfolgeliste für mehr Flexibilität zu ändern. App
ist ein Befehl, der zwei Argumente annimmt: #1 = Anzahl der Frames und #2 = Reihenfolge der Linienzeichnung. Beachten Sie, dass #1 \multiframe{#1}
die letzte in der Liste sein sollte App
.
Der App
Befehl selbst ist eine Whiledo-Schleife, die nichtdiagonale Linien zeichnet.
Bitte ausschneiden und einfügen, um zu zeigen, wie die Animation abläuft.
Code
\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}