From 01298b95d9de1814c984d8861305850ee04b7452 Mon Sep 17 00:00:00 2001 From: Jan Grewe Date: Fri, 23 Feb 2018 17:21:55 +0100 Subject: [PATCH] [plotting] add animations --- plotting/lecture/plotting-chapter.tex | 6 ---- plotting/lecture/plotting.tex | 44 +++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 6 deletions(-) diff --git a/plotting/lecture/plotting-chapter.tex b/plotting/lecture/plotting-chapter.tex index 4dd0a9d..f0ac90c 100644 --- a/plotting/lecture/plotting-chapter.tex +++ b/plotting/lecture/plotting-chapter.tex @@ -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 diff --git a/plotting/lecture/plotting.tex b/plotting/lecture/plotting.tex index 4bc7f2d..badb26e 100644 --- a/plotting/lecture/plotting.tex +++ b/plotting/lecture/plotting.tex @@ -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