day1/session1.tex
changeset 276 4555c3814dd4
parent 265 ac31e2f3754e
child 279 e7ce6f9d7e15
equal deleted inserted replaced
275:71e50184d482 276:4555c3814dd4
    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}
       
   184     \item Python scripts: 
       
   185       \begin{itemize}
       
   186       \item \typ{sslc_allreg.py}
       
   187       \item \typ{sslc_science.py}
       
   188       \end{itemize}
   178   \end{enumerate}
   189   \end{enumerate}
   179 \end{frame}
   190 \end{frame}
   180 
   191 
   181 \begin{frame}[fragile]
   192 \begin{frame}[fragile]
   182 \frametitle{Starting up...}
   193 \frametitle{Starting up \ldots}
   183 \begin{block}{}
   194 \begin{block}{}
   184 \begin{verbatim}
   195 \begin{verbatim}
   185   $ ipython -pylab  
   196   $ ipython -pylab  
   186 \end{verbatim}
   197 \end{verbatim}
   187 \end{block}
   198 \end{block}
   194   In []: ^D(Ctrl-D)
   205   In []: ^D(Ctrl-D)
   195   Do you really want to exit([y]/n)? y
   206   Do you really want to exit([y]/n)? y
   196 \end{lstlisting}
   207 \end{lstlisting}
   197 \end{frame}
   208 \end{frame}
   198 
   209 
   199 \begin{frame}[fragile]
   210 %% \begin{frame}[fragile]
   200 \frametitle{Loops}
   211 %% \frametitle{Loops}
   201 Breaking out of loops
   212 %% Breaking out of loops
   202 \begin{lstlisting}     
   213 %% \begin{lstlisting}     
   203   In []: while True:
   214 %%   In []: while True:
   204     ...:     print "Hello, World!"
   215 %%     ...:     print "Hello, World!"
   205     ...:     
   216 %%     ...:     
   206   Hello, World!
   217 %%   Hello, World!
   207   Hello, World!^C(Ctrl-C)
   218 %%   Hello, World!^C(Ctrl-C)
   208   ------------------------------------
   219 %%   ------------------------------------
   209   KeyboardInterrupt                   
   220 %%   KeyboardInterrupt                   
   210 
   221 
   211 \end{lstlisting}
   222 %% \end{lstlisting}
   212 \end{frame}
   223 %% \end{frame}
   213 
   224 
   214 \section{Plotting}
   225 \section{Plotting}
   215 
   226 
   216 \subsection{Drawing plots}
   227 \subsection{Drawing plots}
   217 \begin{frame}[fragile]
   228 \begin{frame}[fragile]
   222   \includegraphics[height=2in, interpolate=true]{data/firstplot}
   233   \includegraphics[height=2in, interpolate=true]{data/firstplot}
   223     \column{0.8\textwidth}
   234     \column{0.8\textwidth}
   224     \begin{block}{}
   235     \begin{block}{}
   225     \begin{small}
   236     \begin{small}
   226 \begin{lstlisting}
   237 \begin{lstlisting}
   227 In []: x = linspace(0, 2*pi, 51)
   238 In []: x = linspace(0, 2*pi, 50)
   228 In []: plot(x, sin(x))
   239 In []: plot(x, sin(x))
   229 \end{lstlisting}
   240 \end{lstlisting}
   230     \end{small}
   241     \end{small}
   231     \end{block}
   242     \end{block}
   232 \end{columns}
   243 \end{columns}
   244 \end{lstlisting}
   255 \end{lstlisting}
   245 \vspace*{.35in}
   256 \vspace*{.35in}
   246 \begin{block}{\typ{plot(x, y)}}
   257 \begin{block}{\typ{plot(x, y)}}
   247 plots \typ{x} and \typ{y} using default line style and color
   258 plots \typ{x} and \typ{y} using default line style and color
   248 \end{block}
   259 \end{block}
       
   260 %\inctime{10}
   249 \end{frame}
   261 \end{frame}
   250 
   262 
   251 \subsection{Decoration}
   263 \subsection{Decoration}
   252 \begin{frame}[fragile]
   264 \begin{frame}[fragile]
   253 \frametitle{Adding Labels}
   265 \frametitle{Adding Labels}
   277 \begin{frame}[fragile]
   289 \begin{frame}[fragile]
   278 \frametitle{Another example}
   290 \frametitle{Another example}
   279   \begin{lstlisting}
   291   \begin{lstlisting}
   280 In []: clf()
   292 In []: clf()
   281 #Clears the plot area.
   293 #Clears the plot area.
   282 In []: y = linspace(0, 2*pi, 51)
   294 In []: y = linspace(0, 2*pi, 50)
   283 In []: plot(y, sin(2*y))
   295 In []: plot(y, sin(2*y))
   284 In []: xlabel('y')
   296 In []: xlabel('y')
   285 In []: ylabel('sin(2y)')
   297 In []: ylabel('sin(2y)')
   286   \end{lstlisting}
   298   \end{lstlisting}
   287 \emphbar{By default plots would be overlaid!}
       
   288 \end{frame}
   299 \end{frame}
   289 
   300 
   290 \subsection{More decoration}
   301 \subsection{More decoration}
   291 \begin{frame}[fragile]
   302 \begin{frame}[fragile]
   292 \frametitle{Title and Legends}
   303 \frametitle{Title and Legends}
   306   \end{center}
   317   \end{center}
   307 \end{frame}
   318 \end{frame}
   308 
   319 
   309 \begin{frame}[fragile]
   320 \begin{frame}[fragile]
   310 \frametitle{Legend Placement}
   321 \frametitle{Legend Placement}
   311 
       
   312 \begin{block}{}
   322 \begin{block}{}
   313     \small
   323     \small
   314 \begin{lstlisting}
   324 \begin{lstlisting}
   315 In []: legend(['sin(2y)'], loc='center')
   325 In []: legend(['sin(2y)'], loc = 'center')
   316 \end{lstlisting}
   326 \end{lstlisting}
   317 \end{block}
   327 \end{block}
   318 
   328 
   319 \begin{columns}
   329 \begin{columns}
   320     \column{0.6\textwidth}
   330     \column{0.6\textwidth}
   346 \end{lstlisting}
   356 \end{lstlisting}
   347 %\vspace*{-0.2in}
   357 %\vspace*{-0.2in}
   348 \begin{center}
   358 \begin{center}
   349   \includegraphics[height=2in, interpolate=true]{data/loc}  
   359   \includegraphics[height=2in, interpolate=true]{data/loc}  
   350 \end{center}
   360 \end{center}
       
   361 %\inctime{10}
   351 \end{frame}
   362 \end{frame}
   352 
   363 
   353 \begin{frame}[fragile]
   364 \begin{frame}[fragile]
   354 \frametitle{Saving \& Closing}
   365 \frametitle{Saving \& Closing}
   355 \begin{lstlisting}
   366 \begin{lstlisting}
   359 \end{lstlisting}
   370 \end{lstlisting}
   360 \end{frame}
   371 \end{frame}
   361 
   372 
   362 \section{Multiple plots}
   373 \section{Multiple plots}
   363 \begin{frame}[fragile]
   374 \begin{frame}[fragile]
       
   375 \frametitle{Overlaid Plots}
       
   376 \begin{lstlisting}
       
   377 In []: clf()
       
   378 In []: plot(y, sin(y))
       
   379 In []: plot(y, cos(y))
       
   380 In []: xlabel('y')
       
   381 In []: ylabel('f(y)')
       
   382 In []: legend(['sin(y)', 'cos(y)']) 
       
   383 \end{lstlisting}
       
   384 \emphbar{By default plots would be overlaid!}
       
   385 \end{frame}
       
   386 
       
   387 \begin{frame}[fragile]
   364 \frametitle{Plotting separate figures}
   388 \frametitle{Plotting separate figures}
   365 \begin{lstlisting}
   389 \begin{lstlisting}
       
   390 In []: clf()
   366 In []: figure(1)
   391 In []: figure(1)
   367 In []: plot(y, sin(y))
   392 In []: plot(y, sin(y))
   368 In []: figure(2)
   393 In []: figure(2)
   369 In []: plot(y, cos(y))
   394 In []: plot(y, cos(y))
   370 In []: figure(1)
   395 In []: figure(1)
   379 \vspace{-0.15in}
   404 \vspace{-0.15in}
   380 \begin{lstlisting}
   405 \begin{lstlisting}
   381 In []: plot(y, sin(y), 'g')
   406 In []: plot(y, sin(y), 'g')
   382 
   407 
   383 In []: clf()
   408 In []: clf()
   384 In []: plot(y, sin(y), linewidth=2)
   409 In []: plot(y, sin(y), 'g', linewidth=2)
   385 \end{lstlisting}
   410 \end{lstlisting}
   386 \vspace*{-0.2in}
   411 \vspace*{-0.2in}
   387 \begin{center}
   412 \begin{center}
   388   \includegraphics[height=2.2in, interpolate=true]{data/green}  
   413   \includegraphics[height=2.2in, interpolate=true]{data/green}  
   389 \end{center}
   414 \end{center}
       
   415 %\inctime{10}
   390 \end{frame}
   416 \end{frame}
   391 
   417 
   392 \begin{frame}[fragile]
   418 \begin{frame}[fragile]
   393 \frametitle{Annotating}
   419 \frametitle{Annotating}
   394 \vspace*{-0.15in}
   420 \vspace*{-0.15in}
   395 \begin{lstlisting}
   421 \begin{lstlisting}
   396 In []: annotate('local max', 
   422 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}
   423 \end{lstlisting}
   402 \vspace*{-0.2in}
   424 \vspace*{-0.2in}
   403 \begin{center}
   425 \begin{center}
   404   \includegraphics[height=2in, interpolate=true]{data/annotate}  
   426   \includegraphics[height=2in, interpolate=true]{data/annotate}  
   405 \end{center}
   427 \end{center}
   413 In []: ymin, ymax = ylim() 
   435 In []: ymin, ymax = ylim() 
   414 
   436 
   415 In []: xmax = 2*pi
   437 In []: xmax = 2*pi
   416 #Set the axes limits
   438 #Set the axes limits
   417 In []: xlim(xmin, xmax) 
   439 In []: xlim(xmin, xmax) 
   418 In []: ylim(ymin, ymax) 
   440 In []: ylim(ymin-0.2, ymax+0.2) 
   419   \end{lstlisting}
   441   \end{lstlisting}
   420 \end{frame}
   442 \end{frame}
   421 
   443 
   422 \begin{frame}[fragile]
   444 \begin{frame}[fragile]
   423 \frametitle{Review Problem}
   445 \frametitle{Review Problem}
   426 \item Add a legend
   448 \item Add a legend
   427 \item Annotate the origin
   449 \item Annotate the origin
   428 \item Set axis limits to the range of x
   450 \item Set axis limits to the range of x
   429 \end{enumerate}
   451 \end{enumerate}
   430 \begin{lstlisting}
   452 \begin{lstlisting}
   431 In []: x=linspace(-5*pi, 5*pi, 501)
   453 In []: x=linspace(-5*pi, 5*pi, 500)
   432 In []: plot(x, x, 'b')
   454 In []: plot(x, x, 'b')
   433 In []: plot(x, -x, 'b')
   455 In []: plot(x, -x, 'b')
   434 \end{lstlisting}
   456 \end{lstlisting}
   435 $\vdots$
   457 $\vdots$
   436 \end{frame}
   458 \end{frame}
   437 
   459 
   438 \section{Exercises}
       
   439 \begin{frame}[fragile]
   460 \begin{frame}[fragile]
   440 \frametitle{Review Problem \ldots}
   461 \frametitle{Review Problem \ldots}
   441 \small{
       
   442 \begin{lstlisting}
   462 \begin{lstlisting}
   443 In []: plot(x, sin(x), 'g', linewidth=2)
   463 In []: plot(x, sin(x), 'g', linewidth=2)
   444 In []: plot(x, x*sin(x), 'r', linewidth=3)
   464 In []: plot(x, x*sin(x), 'r', 
   445 \end{lstlisting}
   465             linewidth=3)
   446 
   466 \end{lstlisting}
   447 \begin{lstlisting}
   467 \begin{lstlisting}
   448 In []: legend(['x', '-x', 'sin(x)', 'xsin(x)'])
   468 In []: legend(['x', '-x', 'sin(x)', 
   449 In []: annotate('origin', 
   469                'xsin(x)'])
   450                  xy=(0, 0), 
   470 In []: annotate('origin', xy = (0, 0))
   451                  xytext=(0, -7),
   471 In []: xlim(-5*pi, 5*pi)
   452                  arrowprops=dict(
   472 In []: ylim(-5*pi, 5*pi)
   453                  shrink=0.05))
   473 \end{lstlisting}
   454 In []: xlim(5*pi, 5*pi)
   474 \end{frame}
   455 In []: ylim(5*pi, 5*pi)
   475 
   456 \end{lstlisting}
       
   457 }
       
   458 \end{frame}
       
   459 \begin{frame}
   476 \begin{frame}
   460   \frametitle{What did we learn?}
   477   \frametitle{What did we learn?}
   461   \begin{itemize}
   478   \begin{itemize}
   462     \item Creating simple plots.
   479     \item Creating simple plots.
   463     \item Adding labels and legends.
   480     \item Adding labels and legends.
   465     \item Changing the looks: size, linewidth
   482     \item Changing the looks: size, linewidth
   466   \end{itemize}
   483   \end{itemize}
   467   \begin{block}{Note}
   484   \begin{block}{Note}
   468     \centerline{\alert{Don't Close \typ{IPython}}}
   485     \centerline{\alert{Don't Close \typ{IPython}}}
   469   \end{block}
   486   \end{block}
       
   487 %%\inctime{10}
   470 \end{frame}
   488 \end{frame}
   471 
   489 
   472 \end{document}
   490 \end{document}
   473 
   491