day1/session1.tex
changeset 155 069a9aed1027
parent 147 6874a667dc4e
child 171 29c0c504750c
equal deleted inserted replaced
154:66b117b7edc7 155:069a9aed1027
     1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     2 % Tutorial slides on Python.
     2 %Tutorial slides on Python.
     3 %
     3 %
     4 % Author: Prabhu Ramachandran <prabhu at aero.iitb.ac.in>
     4 % Author: FOSSEE 
     5 % Copyright (c) 2005-2009, Prabhu Ramachandran
     5 % Copyright (c) 2009, FOSSEE, IIT Bombay
     6 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     6 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     7 
     7 
     8 \documentclass[14pt,compress]{beamer}
     8 \documentclass[14pt,compress]{beamer}
     9 %\documentclass[draft]{beamer}
     9 %\documentclass[draft]{beamer}
    10 %\documentclass[compress,handout]{beamer}
    10 %\documentclass[compress,handout]{beamer}
   148   In []: while True:
   148   In []: while True:
   149     ...:     print "Hello, World!"
   149     ...:     print "Hello, World!"
   150     ...:     
   150     ...:     
   151   Hello, World!
   151   Hello, World!
   152   Hello, World!^C(Ctrl-C)
   152   Hello, World!^C(Ctrl-C)
       
   153   ------------------------------------
       
   154   KeyboardInterrupt                   
       
   155 
   153 \end{lstlisting}
   156 \end{lstlisting}
   154 \end{frame}
   157 \end{frame}
   155 
   158 
   156 \begin{frame}[fragile]
   159 \begin{frame}[fragile]
   157 \frametitle{First Plot}
   160 \frametitle{First Plot}
   158 \begin{columns}
   161 \begin{columns}
   159     \column{0.25\textwidth}
   162     \column{0.25\textwidth}
   160     \hspace*{-0.5in}
   163     \hspace*{-0.5in}
   161   \includegraphics[height=2in, interpolate=true]{data/firstplot}  
   164   \includegraphics[height=2in, interpolate=true]{data/firstplot}  
   162     \column{0.7\textwidth}
   165     \column{0.8\textwidth}
   163     \begin{block}{Code}
   166     \begin{block}{}
   164     \small
   167     \small
   165 \begin{lstlisting}
   168 \begin{lstlisting}
   166 In []: x=linspace(0,2*pi,51)
   169 In []: x = linspace(0, 2*pi, 51)
   167 In []: plot(x,sin(x))
   170 In []: plot(x, sin(x))
   168 \end{lstlisting}
   171 \end{lstlisting}
   169     \small
   172     \small
   170     \end{block}
   173     \end{block}
   171 \end{columns}
   174 \end{columns}
   172 \end{frame}
   175 \end{frame}
   240 
   243 
   241 \begin{frame}[fragile]
   244 \begin{frame}[fragile]
   242 \frametitle{Changing Legend Placement}
   245 \frametitle{Changing Legend Placement}
   243 \vspace*{-0.1in}
   246 \vspace*{-0.1in}
   244 \begin{lstlisting}
   247 \begin{lstlisting}
   245 In []: legend(['sin(2y)'], loc=(0.75,0.1)) 
   248 In []: legend(['sin(2y)'], loc=(.8,.1)) 
   246 #(x,y) is position of lower-left 
   249 #(x,y) is position of lower-left 
   247 #corner of legend.
   250 #corner of legend box.
   248 \end{lstlisting}
   251 \end{lstlisting}
   249 %\vspace*{-0.2in}
   252 %\vspace*{-0.2in}
   250 \begin{center}
   253 \begin{center}
   251   \includegraphics[height=2in, interpolate=true]{data/loc}  
   254   \includegraphics[height=2in, interpolate=true]{data/loc}  
   252 \end{center}
   255 \end{center}
   296 
   299 
   297 \begin{frame}[fragile]
   300 \begin{frame}[fragile]
   298 \frametitle{Multiple Figures}
   301 \frametitle{Multiple Figures}
   299 \begin{lstlisting}
   302 \begin{lstlisting}
   300 In []: figure(1)
   303 In []: figure(1)
   301 In []: plot(x, sin(x))
   304 In []: plot(y, sin(y))
   302 In []: figure(2)
   305 In []: figure(2)
   303 In []: plot(x, cos(x))
   306 In []: plot(y, cos(y))
   304 In []: figure(1)
   307 In []: figure(1)
   305 In []: title('sin(x)')
   308 In []: title('sin(y)')
       
   309 In []: close()
       
   310 In []: close()
   306 \end{lstlisting}
   311 \end{lstlisting}
   307 \end{frame}
   312 \end{frame}
   308 
   313 
   309 \begin{frame}[fragile]
   314 \begin{frame}[fragile]
   310 \frametitle{Showing it better}
   315 \frametitle{Showing it better}
   311 \vspace{-0.15in}
   316 \vspace{-0.15in}
   312 \begin{lstlisting}
   317 \begin{lstlisting}
   313 In []: plot(y, sin(y), 'g')
   318 In []: plot(y, sin(y), 'g')
   314 # plots the curve using green color
   319 
   315 
   320 In []: clf()
   316 In []: plot(y, sin(y), linewidth=2)
   321 In []: plot(y, sin(y), linewidth=2)
   317 # sets the linewidth to 2  
       
   318 \end{lstlisting}
   322 \end{lstlisting}
   319 \vspace*{-0.2in}
   323 \vspace*{-0.2in}
   320 \begin{center}
   324 \begin{center}
   321   \includegraphics[height=2in, interpolate=true]{data/green}  
   325   \includegraphics[height=2.2in, interpolate=true]{data/green}  
   322 \end{center}
   326 \end{center}
   323 \end{frame}
   327 \end{frame}
   324 
   328 
   325 \begin{frame}[fragile]
   329 \begin{frame}[fragile]
   326 \frametitle{Annotating}
   330 \frametitle{Annotating}
   327 \vspace*{-0.15in}
   331 \vspace*{-0.15in}
   328 \begin{lstlisting}
   332 \begin{lstlisting}
   329 In []: annotate('local max', 
   333 In []: annotate('local max', 
   330        xy=(2, 1), 
   334        xy=(1.5, 1), 
   331        xytext=(3, 1.5),
   335        xytext=(2.5, .8),
   332        arrowprops=dict(
   336        arrowprops=dict(
   333        shrink=0.05),)
   337        shrink=0.05),)
   334 \end{lstlisting}
   338 \end{lstlisting}
   335 \vspace*{-0.2in}
   339 \vspace*{-0.2in}
   336 \begin{center}
   340 \begin{center}
   343   \begin{lstlisting}
   347   \begin{lstlisting}
   344 #Get the axes limits
   348 #Get the axes limits
   345 In []: xmin, xmax = xlim() 
   349 In []: xmin, xmax = xlim() 
   346 In []: ymin, ymax = ylim() 
   350 In []: ymin, ymax = ylim() 
   347 
   351 
       
   352 In []: xmax = 2*pi
   348 #Set the axes limits
   353 #Set the axes limits
   349 In []: xlim(xmin, xmax) 
   354 In []: xlim(xmin, xmax) 
   350 In []: ylim(ymin, ymax) 
   355 In []: ylim(ymin, ymax) 
   351   \end{lstlisting}
   356   \end{lstlisting}
   352 \end{frame}
   357 \end{frame}
   353 
   358 
   354 \begin{frame}[fragile]
   359 \begin{frame}[fragile]
       
   360 \frametitle{Review Problem}
       
   361 \begin{enumerate}
       
   362 \item Plot x, -x, sin(x), xsin(x) in the range $-5\pi$ to $5\pi$
       
   363 \item Add a legend
       
   364 \item Annotate the origin
       
   365 \item Set axis limits to the range of x
       
   366 \end{enumerate}
       
   367 \begin{lstlisting}
       
   368 In []: x=linspace(-5*pi, 5*pi, 501)
       
   369 In []: plot(x, x, 'b')
       
   370 In []: plot(x, -x, 'b')
       
   371 \end{lstlisting}
       
   372 $\vdots$
       
   373 \end{frame}
       
   374 
       
   375 \begin{frame}[fragile]
       
   376 \frametitle{Review Problem \ldots}
       
   377 \small{
       
   378 \begin{lstlisting}
       
   379 In []: plot(x, sin(x), 'g', linewidth=2)
       
   380 In []: plot(x, x*sin(x), 'r', linewidth=3)
       
   381 \end{lstlisting}
       
   382 
       
   383 \begin{lstlisting}
       
   384 In []: legend(['x', '-x', 'sin(x)', 'xsin(x)'])
       
   385 In []: annotate('origin', 
       
   386                  xy=(0, 0), 
       
   387                  xytext=(0, -7),
       
   388                  arrowprops=dict(
       
   389                  shrink=0.05))
       
   390 In []: xlim(5*pi, 5*pi)
       
   391 In []: ylim(5*pi, 5*pi)
       
   392 \end{lstlisting}
       
   393 }
       
   394 \end{frame}
       
   395 
       
   396 \begin{frame}[fragile]
   355   \begin{center}
   397   \begin{center}
   356   End of Session-1\\
   398   End of Session-1\\
   357   \alert{Don't Close \typ{IPython}}
   399   \alert{Don't Close \typ{IPython}}
   358   \end{center}
   400   \end{center}
   359 \end{frame}
   401 \end{frame}