
나는 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개의 라인이 한 줄씩 순서대로 애니메이션 애니메이션에 나타나기를 원합니다. 원하는 출력을 표시하기 위해 수동으로 애니메이션 GIF를 만들었습니다.
하지만 여기서부터는 계속 진행할 올바른 생각이 없습니다.
Jake의 솔루션
답변해주셔서 감사합니다! 나에게 중요한 외부 파일을 사용하기 때문에 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
이는 더 많은 유연성을 위해 주문 목록을 변경할 수 있는 시도입니다. App
두 개의 인수 #1= 프레임 수 및 #2= 선 그리기 순서를 사용하는 명령입니다. 1위가 목록 \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}