day1/session2.tex
changeset 155 069a9aed1027
parent 153 dc0da25b788b
child 156 6a1388c456f4
child 158 978108b0c02c
equal deleted inserted replaced
154:66b117b7edc7 155:069a9aed1027
     1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     2 %Tutorial slides on Python.
     2 %Tutorial slides on Python.
     3 %
     3 %
     4 % Author: The FOSSEE Group
     4 % Author: FOSSEE
     5 % Copyright (c) 2009, The FOSSEE Group, IIT Bombay
     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}
    71 % }
    71 % }
    72 
    72 
    73 
    73 
    74 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    74 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    75 % Title page
    75 % Title page
    76 \title[Basic Python]{Basic Overview\\}
    76 \title[Plotting using Python]{Plotting experimental data\\}
    77 
    77 
    78 \author[FOSSEE Team] {The FOSSEE Group}
    78 \author[FOSSEE] {FOSSEE}
    79 
    79 
    80 \institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay}
    80 \institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay}
    81 \date[] {31, October 2009\\Day 1, Session 2}
    81 \date[] {31, October 2009\\Day 1, Session 2}
    82 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    82 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    83 
    83 
   121   \frametitle{Outline}
   121   \frametitle{Outline}
   122   \tableofcontents
   122   \tableofcontents
   123   % You might wish to add the option [pausesections]
   123   % You might wish to add the option [pausesections]
   124 \end{frame}
   124 \end{frame}
   125 
   125 
   126 \section{Functions}
       
   127 \begin{frame}{Functions: Definition}
       
   128 \begin{itemize}
       
   129   \item \kwrd{def} keyword
       
   130 \end{itemize}
       
   131 \end{frame}
       
   132 
       
   133 \begin{frame}[fragile]
       
   134 \frametitle{Functions: Example 1}
       
   135   \begin{lstlisting}
       
   136 In []: def plot_sinx():
       
   137    ....:     x = linspace(0, 2*pi, 100)
       
   138    ....:     plt.plot(x, sin(x))
       
   139    ....:     plt.show()
       
   140    ....:    
       
   141 
       
   142 In []: plot_sinx()
       
   143   \end{lstlisting}
       
   144 \end{frame}
       
   145 
       
   146 \begin{frame}[fragile]
       
   147 \frametitle{Functions: Example 2}
       
   148   \begin{lstlisting}
       
   149 In []: def f(x):
       
   150    ....:     return sin(x*x*x)+(3*x*x)
       
   151 
       
   152 In []: x = linspace(0,2*pi, 1000)
       
   153 
       
   154 In []: plt.plot(x, f(x))
       
   155   \end{lstlisting}
       
   156   \inctime{10}
       
   157 \end{frame}
       
   158 
       
   159 \section{Creating and running scripts}
   126 \section{Creating and running scripts}
       
   127 \begin{frame}[fragile]
       
   128 \frametitle{Python Scripts}
       
   129 \begin{itemize}
       
   130 \item Let us now put all the commands used in the review problem into a file. 
       
   131 \item The following commands of IPython help us do this. 
       
   132 \end{itemize}
       
   133 \begin{lstlisting}
       
   134   In []: %hist
       
   135   In []: %hist -n
       
   136 \end{lstlisting}
       
   137 \end{frame}
       
   138 
   160 \begin{frame}
   139 \begin{frame}
   161   {Creating python files}
   140 \frametitle{Python Scripts\ldots}
   162   \begin{itemize}
   141   \begin{itemize}
   163     \item use your editor
   142     \item Open a new file in an \alert{editor}
   164     \item extension \typ{.py}
   143     \item Copy and paste required lines from the output of \typ{\%hist -n}
   165     \item in IPython using \kwrd{\%run}
   144     \item Save the file as \typ{first_plot.py}
   166   \end{itemize}
   145   \end{itemize}
   167 \inctime{5}
   146   \begin{itemize}
   168 \end{frame}
   147   \item run the file in IPython using \typ{\%run first_plot.py}\\
       
   148   \end{itemize}
       
   149 \end{frame}
       
   150 
       
   151 \section{Plotting Points}
       
   152 \begin{frame}[fragile]
       
   153 \frametitle{Simple Pendulum - L and T}
       
   154   \begin{itemize}
       
   155     \item Given data of Length and Time-period of a Simple pendulum 
       
   156     \item We wish to plot L vs. \alert{$T^2$}
       
   157   \end{itemize}    
       
   158 \begin{lstlisting}
       
   159 In []: L = [0.1,  0.2,  0.3,  
       
   160             0.4,  0.5,  0.6,  
       
   161             0.7,  0.8,  0.9]
       
   162 In []: T = [0.6529, 0.8485, 1.0590, 
       
   163             1.2390, 1.4124, 1.5061, 
       
   164             1.6441, 1.7949, 1.8758]
       
   165 \end{lstlisting}
       
   166 \end{frame}
       
   167 
       
   168 \begin{frame}[fragile]
       
   169 \frametitle{Simple Pendulum \ldots}
       
   170 \begin{itemize}
       
   171 \item Let us begin with $L$ vs. \alert{$T$}
       
   172 \end{itemize}
       
   173 \begin{lstlisting}
       
   174   In []: plot(L, T)
       
   175 \end{lstlisting}
       
   176 \begin{itemize}
       
   177 \item But we wish to plot points!
       
   178 \end{itemize}
       
   179 \end{frame}
       
   180 
       
   181 \begin{frame}[fragile]
       
   182 \frametitle{Plotting points}
       
   183 \begin{lstlisting}
       
   184   In []: clf()
       
   185 
       
   186   In []: plot(L, T, 'o')
       
   187   Out[]: [<matplotlib.lines.Line2D object at 0xac17e0c>]
       
   188 
       
   189   In []: clf()
       
   190   In []: plot(L, T, '.')
       
   191   Out[]: [<matplotlib.lines.Line2D object at 0xac17e0c>]
       
   192 \end{lstlisting}
       
   193 \end{frame}
       
   194 
       
   195 \begin{frame}[fragile]
       
   196 \frametitle{Plotting Attributes}
       
   197 \begin{itemize}
       
   198   \item \kwrd{'o'} - Dots
       
   199   \item \kwrd{'-'} - Lines
       
   200   \item \kwrd{'- -'} - Dashed lines
       
   201 \end{itemize}
       
   202 \end{frame}
       
   203 
       
   204 
   169 
   205 
   170 \section{File Handling}
   206 \section{File Handling}
   171 \begin{frame}[fragile]
   207 \begin{frame}[fragile]
   172     \frametitle{File and \kwrd{for}}
   208     \frametitle{File and \kwrd{for}}
   173 \begin{lstlisting}
   209 \begin{lstlisting}
   201   \end{lstlisting}
   237   \end{lstlisting}
   202 \inctime{5}
   238 \inctime{5}
   203 \end{frame}
   239 \end{frame}
   204 
   240 
   205 \section{Plotting points}
   241 \section{Plotting points}
   206 \begin{frame}[fragile]
       
   207 \frametitle{How to plot points?}
       
   208 \begin{lstlisting}
       
   209 In []: plt.plot(x, sin(x), 'ro')
       
   210 Out[]: [<matplotlib.lines.Line2D object at 0xac17e0c>]
       
   211 \end{lstlisting}
       
   212 \begin{itemize}
       
   213   \item \kwrd{'r'},\kwrd{'g'},\kwrd{'b'} for red, green and blue
       
   214   \item \kwrd{'o'} - Dots
       
   215   \item \kwrd{'-'} - Lines
       
   216   \item \kwrd{'- -'} - Dashed lines
       
   217 \end{itemize}
       
   218 \inctime{5}
       
   219 \end{frame}
       
   220 
   242 
   221 \section{Lists}
   243 \section{Lists}
   222 
   244 
   223 \begin{frame}[fragile]
   245 \begin{frame}[fragile]
   224   \frametitle{List creation and indexing}
   246   \frametitle{List creation and indexing}
   254 Out[]: [1, 2, 3, 4, 5, [6, 7]]
   276 Out[]: [1, 2, 3, 4, 5, [6, 7]]
   255 \end{lstlisting}
   277 \end{lstlisting}
   256 \inctime{10}
   278 \inctime{10}
   257 \end{frame}
   279 \end{frame}
   258 
   280 
   259 \section{Modules and import}
       
   260 \begin{frame}{Modules and \typ{import}}
       
   261   \begin{itemize}
       
   262     \item \kwrd{import} x
       
   263     \item \kwrd{from} x \kwrd{import} y
       
   264   \end{itemize}
       
   265 \pause
       
   266 Whats the difference??
       
   267 \inctime{5}
       
   268 \end{frame}
       
   269 
       
   270 \end{document}
   281 \end{document}