[plotting] add animations

This commit is contained in:
Jan Grewe 2018-02-23 17:21:55 +01:00
parent 294b730647
commit 01298b95d9
2 changed files with 44 additions and 6 deletions

View File

@ -16,8 +16,6 @@
\input{plotting}
\subsection{Error bars and error areas}
\subsection{Scatter plot}
\subsection{Histograms}
@ -28,10 +26,6 @@
\subsection{Polar plot}
\subsection{print instead of saveas????}
\subsection{Movies and animations}
\section{TODO}
\begin{itemize}
\item Beispiele schlechter plots sollten mehr Bezug zu den Typen von

View File

@ -629,6 +629,50 @@ documentation.
that should be drawn between two subplots?
\end{important}
\subsection{Animations and movies}
A picture is worth a thousand words and sometimes creating animations
or movies is worth many pictures. They can help understanding complex
or time-dependent developments and may add some variety to a
presentation. The following example shows how a movie can be created
and saved to file. A similar mechanism is available to produce
animations that are supposed to be shown within \matlab{} but for this
we point to the documentation of the \code[movie()]{movie()}
command. The underlying principle is the same, however. The code shown
in listing\,\ref{animationlisting} creates an animation of a
Lissajous figure. The basic steps are:
\begin{enumerate}
\item Create a figure and set some basic properties (lines 7 --- 10).
\item Create a \code[VideoWriter()]{VideoWriter} object that, in this
example, takes the filename and the profile, the mpg-4 compression
profile, as arguments (line 12). For more options see the
documentation.
\item We can set the desired framerate and the quality of the video
(lines 13, 14). Quality is a value between 0 and 100, where 100 is
the best quality but leads to the largest files. The framerate
defines how quickly the individual frames will switched. In our
example, we create 500 frames and the video framerate is
25\,Hz. That is, the movie will have a duration of
$500/25 = 20$\,seconds.
\item Open the destination file (line 16). Opening means that the file
is created and opened for writing. This also implies that is has to
be closed after the whole process (line 31).
\item For each frame of the video, we plot the appropriate data (we
use \code[scatter]{scatter} for this purpose, line 20) and ``grab''
the frame (line 28). Grabbing is similar to making a screenshot of
the figure. The \code{drawnow}{drawnow} command (line 27) is used to
stop the excution of the for loop until the drawing process is
finished.
\item Write the frame to file (line 29).
\item Finally, close the file (line 31).
\end{enumerate}
\lstinputlisting[caption={Making animations and saving them as a
movie.}, label=animationlisting, firstline=3, lastline=33,
basicstyle=\ttfamily\scriptsize]{movie_example.m}
\section{Summary}
A good plot of scientific data displays the data completely and