day1/session1.tex
changeset 264 c3a1de5b8216
parent 247 786aa938a5c3
child 265 ac31e2f3754e
equal deleted inserted replaced
260:1f5fea506927 264:c3a1de5b8216
    47       {#1}
    47       {#1}
    48  \end{beamercolorbox}
    48  \end{beamercolorbox}
    49 }
    49 }
    50 \newcounter{time}
    50 \newcounter{time}
    51 \setcounter{time}{0}
    51 \setcounter{time}{0}
    52 \newcommand{\inctime}[1]{\addtocounter{time}{#1}{\tiny \thetime\ m}}
    52 \newcommand{%\inctime}[1]{\addtocounter{time}{#1}{\tiny \thetime\ m}}
    53 
    53 
    54 \newcommand{\typ}[1]{\lstinline{#1}}
    54 \newcommand{\typ}[1]{\lstinline{#1}}
    55 
    55 
    56 \newcommand{\kwrd}[1]{ \texttt{\textbf{\color{blue}{#1}}}  }
    56 \newcommand{\kwrd}[1]{ \texttt{\textbf{\color{blue}{#1}}}  }
    57 
    57 
    75 \title[Interactive Plotting]{Python for Science and Engg: Interactive Plotting}
    75 \title[Interactive Plotting]{Python for Science and Engg: Interactive Plotting}
    76 
    76 
    77 \author[FOSSEE] {FOSSEE}
    77 \author[FOSSEE] {FOSSEE}
    78 
    78 
    79 \institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay}
    79 \institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay}
    80 \date[] {31, October 2009\\Day 1, Session 1}
    80 \date[] {31 October, 2009\\Day 1, Session 1}
    81 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    81 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    82 
    82 
    83 %\pgfdeclareimage[height=0.75cm]{iitmlogo}{iitmlogo}
    83 %\pgfdeclareimage[height=0.75cm]{iitmlogo}{iitmlogo}
    84 %\logo{\pgfuseimage{iitmlogo}}
    84 %\logo{\pgfuseimage{iitmlogo}}
    85 
    85 
   104 
   104 
   105 % If you wish to uncover everything in a step-wise fashion, uncomment
   105 % If you wish to uncover everything in a step-wise fashion, uncomment
   106 % the following command: 
   106 % the following command: 
   107 %\beamerdefaultoverlayspecification{<+->}
   107 %\beamerdefaultoverlayspecification{<+->}
   108 
   108 
   109 %\includeonlyframes{current,current1,current2,current3,current4,current5,current6}
   109 %%\includeonlyframes{current,current1,current2,current3,current4,current5,current6}
   110 
   110 
   111 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   111 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   112 % DOCUMENT STARTS
   112 % DOCUMENT STARTS
   113 \begin{document}
   113 \begin{document}
   114 
   114 
   127   \begin{description}
   127   \begin{description}
   128 	\item[Session 1] Sat 09:00--10:00
   128 	\item[Session 1] Sat 09:00--10:00
   129 	\item[Session 2] Sat 10:05--11:05
   129 	\item[Session 2] Sat 10:05--11:05
   130 	\item[Session 3] Sat 11:20--12:20
   130 	\item[Session 3] Sat 11:20--12:20
   131 	\item[Session 4] Sat 12:25--13:25
   131 	\item[Session 4] Sat 12:25--13:25
   132         \item[Quiz -1]   Sat 14:25--14:40
   132         \item[Quiz 1] Sat 14:25--14:40
   133         \item[Session 5] Sat 14:40--15:40
   133         \item[Session 5] Sat 14:40--15:40
   134         \item[Session 6] Sat 15:55--16:55
   134         \item[Session 6] Sat 15:55--16:55
   135         \item[Quiz -2]   Sat 17:00--17:15
   135         \item[Quiz 2] Sat 17:00--17:15
   136   \end{description}
   136   \end{description}
   137 \end{frame}
   137 \end{frame}
   138 
   138 
   139 \begin{frame}
   139 \begin{frame}
   140   \frametitle{Workshop Schedule: Day 2}
   140   \frametitle{Workshop Schedule: Day 2}
   141   \begin{description}
   141   \begin{description}
   142 	\item[Session 1] Sun 09:00--10:00
   142 	\item[Session 1] Sun 09:00--10:00
   143 	\item[Session 2] Sun 10:05--11:05
   143 	\item[Session 2] Sun 10:05--11:05
   144 	\item[Session 3] Sun 11:20--12:20
   144 	\item[Session 3] Sun 11:20--12:20
   145 	\item[Session 4] Sun 12:25--13:25
   145 	\item[Session 4] Sun 12:25--13:25
   146         \item[Quiz -1]   Sun 14:25--14:40
   146         \item[Quiz 1] Sun 14:25--14:40
   147         \item[Session 5] Sun 14:40--15:40
   147         \item[Session 5] Sun 14:40--15:40
   148         \item[Session 6] Sun 15:55--16:55
   148         \item[Session 6] Sun 15:55--16:55
   149         \item[Quiz -2]   Sun 17:00--17:15
   149         \item[Quiz 2] Sun 17:00--17:15
   150   \end{description}
   150   \end{description}
   151 \end{frame}
   151 \end{frame}
   152 
   152 
   153 \begin{frame}
   153 \begin{frame}
   154   \frametitle{About the Workshop}
   154   \frametitle{About the Workshop}
   159   \end{itemize}
   159   \end{itemize}
   160   \end{block}  
   160   \end{block}  
   161 
   161 
   162   \begin{block}{Goal: Successful participants will be able to}
   162   \begin{block}{Goal: Successful participants will be able to}
   163     \begin{itemize}
   163     \begin{itemize}
   164       \item Use Python as plotting, computational toolkit
   164       \item Use Python as plotting, computational tool
   165       \item Understand how Python can be used as scripting and problem solving language.
   165       \item Understand how Python can be used as a scripting and problem solving language.
   166       \item Train the students to use Python for the same
   166       \item Train students for the same
   167     \end{itemize}
   167     \end{itemize}
   168   \end{block}
   168   \end{block}
   169 \end{frame}
   169 \end{frame}
   170 
   170 
   171 \section{Getting started}
   171 \section{Getting started}
   172 \begin{frame}
   172 \begin{frame}
   173 \frametitle{Checklist}
   173 \frametitle{Checklist}
   174   \begin{enumerate}
   174   \begin{enumerate}
   175     \item IPython: Type ipython at the command line. Is it available?
   175     \item IPython
   176     \item Editor: We recommend scite.
   176     \item Editor: We recommend scite.
   177     \item Data files: Make sure you have all data files.
   177     \item Data files: 
       
   178       \begin{itemize}
       
   179       \item \typ{sslc1.txt}
       
   180       \item \typ{pendulum.txt}
       
   181       \item \typ{points.txt}
       
   182       \item \typ{pos.txt}
       
   183       \end{itemize}
   178   \end{enumerate}
   184   \end{enumerate}
   179 \end{frame}
   185 \end{frame}
   180 
   186 
   181 \begin{frame}[fragile]
   187 \begin{frame}[fragile]
   182 \frametitle{Starting up...}
   188 \frametitle{Starting up \ldots}
   183 \begin{block}{}
   189 \begin{block}{}
   184 \begin{verbatim}
   190 \begin{verbatim}
   185   $ ipython -pylab  
   191   $ ipython -pylab  
   186 \end{verbatim}
   192 \end{verbatim}
   187 \end{block}
   193 \end{block}
   194   In []: ^D(Ctrl-D)
   200   In []: ^D(Ctrl-D)
   195   Do you really want to exit([y]/n)? y
   201   Do you really want to exit([y]/n)? y
   196 \end{lstlisting}
   202 \end{lstlisting}
   197 \end{frame}
   203 \end{frame}
   198 
   204 
   199 \begin{frame}[fragile]
   205 %% \begin{frame}[fragile]
   200 \frametitle{Loops}
   206 %% \frametitle{Loops}
   201 Breaking out of loops
   207 %% Breaking out of loops
   202 \begin{lstlisting}     
   208 %% \begin{lstlisting}     
   203   In []: while True:
   209 %%   In []: while True:
   204     ...:     print "Hello, World!"
   210 %%     ...:     print "Hello, World!"
   205     ...:     
   211 %%     ...:     
   206   Hello, World!
   212 %%   Hello, World!
   207   Hello, World!^C(Ctrl-C)
   213 %%   Hello, World!^C(Ctrl-C)
   208   ------------------------------------
   214 %%   ------------------------------------
   209   KeyboardInterrupt                   
   215 %%   KeyboardInterrupt                   
   210 
   216 
   211 \end{lstlisting}
   217 %% \end{lstlisting}
   212 \end{frame}
   218 %% \end{frame}
   213 
   219 
   214 \section{Plotting}
   220 \section{Plotting}
   215 
   221 
   216 \subsection{Drawing plots}
   222 \subsection{Drawing plots}
   217 \begin{frame}[fragile]
   223 \begin{frame}[fragile]
   222   \includegraphics[height=2in, interpolate=true]{data/firstplot}
   228   \includegraphics[height=2in, interpolate=true]{data/firstplot}
   223     \column{0.8\textwidth}
   229     \column{0.8\textwidth}
   224     \begin{block}{}
   230     \begin{block}{}
   225     \begin{small}
   231     \begin{small}
   226 \begin{lstlisting}
   232 \begin{lstlisting}
   227 In []: x = linspace(0, 2*pi, 51)
   233 In []: x = linspace(0, 2*pi, 50)
   228 In []: plot(x, sin(x))
   234 In []: plot(x, sin(x))
   229 \end{lstlisting}
   235 \end{lstlisting}
   230     \end{small}
   236     \end{small}
   231     \end{block}
   237     \end{block}
   232 \end{columns}
   238 \end{columns}
   244 \end{lstlisting}
   250 \end{lstlisting}
   245 \vspace*{.35in}
   251 \vspace*{.35in}
   246 \begin{block}{\typ{plot(x, y)}}
   252 \begin{block}{\typ{plot(x, y)}}
   247 plots \typ{x} and \typ{y} using default line style and color
   253 plots \typ{x} and \typ{y} using default line style and color
   248 \end{block}
   254 \end{block}
       
   255 %\inctime{10}
   249 \end{frame}
   256 \end{frame}
   250 
   257 
   251 \subsection{Decoration}
   258 \subsection{Decoration}
   252 \begin{frame}[fragile]
   259 \begin{frame}[fragile]
   253 \frametitle{Adding Labels}
   260 \frametitle{Adding Labels}
   277 \begin{frame}[fragile]
   284 \begin{frame}[fragile]
   278 \frametitle{Another example}
   285 \frametitle{Another example}
   279   \begin{lstlisting}
   286   \begin{lstlisting}
   280 In []: clf()
   287 In []: clf()
   281 #Clears the plot area.
   288 #Clears the plot area.
   282 In []: y = linspace(0, 2*pi, 51)
   289 In []: y = linspace(0, 2*pi, 50)
   283 In []: plot(y, sin(2*y))
   290 In []: plot(y, sin(2*y))
   284 In []: xlabel('y')
   291 In []: xlabel('y')
   285 In []: ylabel('sin(2y)')
   292 In []: ylabel('sin(2y)')
   286   \end{lstlisting}
   293   \end{lstlisting}
   287 \emphbar{By default plots would be overlaid!}
       
   288 \end{frame}
   294 \end{frame}
   289 
   295 
   290 \subsection{More decoration}
   296 \subsection{More decoration}
   291 \begin{frame}[fragile]
   297 \begin{frame}[fragile]
   292 \frametitle{Title and Legends}
   298 \frametitle{Title and Legends}
   306   \end{center}
   312   \end{center}
   307 \end{frame}
   313 \end{frame}
   308 
   314 
   309 \begin{frame}[fragile]
   315 \begin{frame}[fragile]
   310 \frametitle{Legend Placement}
   316 \frametitle{Legend Placement}
   311 
       
   312 \begin{block}{}
   317 \begin{block}{}
   313     \small
   318     \small
   314 \begin{lstlisting}
   319 \begin{lstlisting}
   315 In []: legend(['sin(2y)'], loc='center')
   320 In []: legend(['sin(2y)'], loc = 'center')
   316 \end{lstlisting}
   321 \end{lstlisting}
   317 \end{block}
   322 \end{block}
   318 
   323 
   319 \begin{columns}
   324 \begin{columns}
   320     \column{0.6\textwidth}
   325     \column{0.6\textwidth}
   346 \end{lstlisting}
   351 \end{lstlisting}
   347 %\vspace*{-0.2in}
   352 %\vspace*{-0.2in}
   348 \begin{center}
   353 \begin{center}
   349   \includegraphics[height=2in, interpolate=true]{data/loc}  
   354   \includegraphics[height=2in, interpolate=true]{data/loc}  
   350 \end{center}
   355 \end{center}
       
   356 %\inctime{10}
   351 \end{frame}
   357 \end{frame}
   352 
   358 
   353 \begin{frame}[fragile]
   359 \begin{frame}[fragile]
   354 \frametitle{Saving \& Closing}
   360 \frametitle{Saving \& Closing}
   355 \begin{lstlisting}
   361 \begin{lstlisting}
   359 \end{lstlisting}
   365 \end{lstlisting}
   360 \end{frame}
   366 \end{frame}
   361 
   367 
   362 \section{Multiple plots}
   368 \section{Multiple plots}
   363 \begin{frame}[fragile]
   369 \begin{frame}[fragile]
       
   370 \frametitle{Overlaid Plots}
       
   371 \begin{lstlisting}
       
   372 In []: clf()
       
   373 In []: plot(y, sin(y))
       
   374 In []: plot(y, cos(y))
       
   375 In []: xlabel('y')
       
   376 In []: ylabel('f(y)')
       
   377 In []: legend(['sin(y)', 'cos(y)']) 
       
   378 \end{lstlisting}
       
   379 \emphbar{By default plots would be overlaid!}
       
   380 \end{frame}
       
   381 
       
   382 \begin{frame}[fragile]
   364 \frametitle{Plotting separate figures}
   383 \frametitle{Plotting separate figures}
   365 \begin{lstlisting}
   384 \begin{lstlisting}
       
   385 In []: clf()
   366 In []: figure(1)
   386 In []: figure(1)
   367 In []: plot(y, sin(y))
   387 In []: plot(y, sin(y))
   368 In []: figure(2)
   388 In []: figure(2)
   369 In []: plot(y, cos(y))
   389 In []: plot(y, cos(y))
   370 In []: figure(1)
   390 In []: figure(1)
   379 \vspace{-0.15in}
   399 \vspace{-0.15in}
   380 \begin{lstlisting}
   400 \begin{lstlisting}
   381 In []: plot(y, sin(y), 'g')
   401 In []: plot(y, sin(y), 'g')
   382 
   402 
   383 In []: clf()
   403 In []: clf()
   384 In []: plot(y, sin(y), linewidth=2)
   404 In []: plot(y, sin(y), 'g', linewidth=2)
   385 \end{lstlisting}
   405 \end{lstlisting}
   386 \vspace*{-0.2in}
   406 \vspace*{-0.2in}
   387 \begin{center}
   407 \begin{center}
   388   \includegraphics[height=2.2in, interpolate=true]{data/green}  
   408   \includegraphics[height=2.2in, interpolate=true]{data/green}  
   389 \end{center}
   409 \end{center}
       
   410 %\inctime{10}
   390 \end{frame}
   411 \end{frame}
   391 
   412 
   392 \begin{frame}[fragile]
   413 \begin{frame}[fragile]
   393 \frametitle{Annotating}
   414 \frametitle{Annotating}
   394 \vspace*{-0.15in}
   415 \vspace*{-0.15in}
   395 \begin{lstlisting}
   416 \begin{lstlisting}
   396 In []: annotate('local max', 
   417 In []: annotate('local max', xy=(1.5, 1))
   397        xy=(1.5, 1), 
       
   398        xytext=(2.5, .8),
       
   399        arrowprops=dict(
       
   400        shrink=0.05),)
       
   401 \end{lstlisting}
   418 \end{lstlisting}
   402 \vspace*{-0.2in}
   419 \vspace*{-0.2in}
   403 \begin{center}
   420 \begin{center}
   404   \includegraphics[height=2in, interpolate=true]{data/annotate}  
   421   \includegraphics[height=2in, interpolate=true]{data/annotate}  
   405 \end{center}
   422 \end{center}
   413 In []: ymin, ymax = ylim() 
   430 In []: ymin, ymax = ylim() 
   414 
   431 
   415 In []: xmax = 2*pi
   432 In []: xmax = 2*pi
   416 #Set the axes limits
   433 #Set the axes limits
   417 In []: xlim(xmin, xmax) 
   434 In []: xlim(xmin, xmax) 
   418 In []: ylim(ymin, ymax) 
   435 In []: ylim(ymin-0.2, ymax+0.2) 
   419   \end{lstlisting}
   436   \end{lstlisting}
   420 \end{frame}
   437 \end{frame}
   421 
   438 
   422 \begin{frame}[fragile]
   439 \begin{frame}[fragile]
   423 \frametitle{Review Problem}
   440 \frametitle{Review Problem}
   426 \item Add a legend
   443 \item Add a legend
   427 \item Annotate the origin
   444 \item Annotate the origin
   428 \item Set axis limits to the range of x
   445 \item Set axis limits to the range of x
   429 \end{enumerate}
   446 \end{enumerate}
   430 \begin{lstlisting}
   447 \begin{lstlisting}
   431 In []: x=linspace(-5*pi, 5*pi, 501)
   448 In []: x=linspace(-5*pi, 5*pi, 500)
   432 In []: plot(x, x, 'b')
   449 In []: plot(x, x, 'b')
   433 In []: plot(x, -x, 'b')
   450 In []: plot(x, -x, 'b')
   434 \end{lstlisting}
   451 \end{lstlisting}
   435 $\vdots$
   452 $\vdots$
   436 \end{frame}
   453 \end{frame}
   437 
   454 
   438 \section{Exercises}
       
   439 \begin{frame}[fragile]
   455 \begin{frame}[fragile]
   440 \frametitle{Review Problem \ldots}
   456 \frametitle{Review Problem \ldots}
   441 \small{
       
   442 \begin{lstlisting}
   457 \begin{lstlisting}
   443 In []: plot(x, sin(x), 'g', linewidth=2)
   458 In []: plot(x, sin(x), 'g', linewidth=2)
   444 In []: plot(x, x*sin(x), 'r', linewidth=3)
   459 In []: plot(x, x*sin(x), 'r', 
   445 \end{lstlisting}
   460             linewidth=3)
   446 
   461 \end{lstlisting}
   447 \begin{lstlisting}
   462 \begin{lstlisting}
   448 In []: legend(['x', '-x', 'sin(x)', 'xsin(x)'])
   463 In []: legend(['x', '-x', 'sin(x)', 
   449 In []: annotate('origin', 
   464                'xsin(x)'])
   450                  xy=(0, 0), 
   465 In []: annotate('origin', xy = (0, 0))
   451                  xytext=(0, -7),
   466 In []: xlim(-5*pi, 5*pi)
   452                  arrowprops=dict(
   467 In []: ylim(-5*pi, 5*pi)
   453                  shrink=0.05))
   468 \end{lstlisting}
   454 In []: xlim(5*pi, 5*pi)
   469 \end{frame}
   455 In []: ylim(5*pi, 5*pi)
   470 
   456 \end{lstlisting}
       
   457 }
       
   458 \end{frame}
       
   459 \begin{frame}
   471 \begin{frame}
   460   \frametitle{What did we learn?}
   472   \frametitle{What did we learn?}
   461   \begin{itemize}
   473   \begin{itemize}
   462     \item Creating simple plots.
   474     \item Creating simple plots.
   463     \item Adding labels and legends.
   475     \item Adding labels and legends.
   465     \item Changing the looks: size, linewidth
   477     \item Changing the looks: size, linewidth
   466   \end{itemize}
   478   \end{itemize}
   467   \begin{block}{Note}
   479   \begin{block}{Note}
   468     \centerline{\alert{Don't Close \typ{IPython}}}
   480     \centerline{\alert{Don't Close \typ{IPython}}}
   469   \end{block}
   481   \end{block}
       
   482 %%\inctime{10}
   470 \end{frame}
   483 \end{frame}
   471 
   484 
   472 \end{document}
   485 \end{document}
   473 
   486