day1/session2.tex
changeset 194 7288d3867df2
parent 193 a31b0e76c0fb
parent 188 15f29c7fd925
child 195 89e912d8c87f
equal deleted inserted replaced
193:a31b0e76c0fb 194:7288d3867df2
    71 % }
    71 % }
    72 
    72 
    73 
    73 
    74 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    74 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    75 % Title page
    75 % Title page
    76 \title[Plotting using Python]{Plotting experimental data\\}
    76 \title[Plotting using Python]{Python for Science and Egg. Plotting experimental data}
    77 
    77 
    78 \author[FOSSEE] {FOSSEE}
    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}
   124 \end{frame}
   124 \end{frame}
   125 
   125 
   126 \begin{frame}
   126 \begin{frame}
   127 \frametitle{Why we didn't close the IPython??}
   127 \frametitle{Why we didn't close the IPython??}
   128 \begin{itemize}
   128 \begin{itemize}
   129   \item Because all the command history is lost
   129   \item IPython provides a convenient feature
   130   \item We can go back, edit, and re-execute our commands
   130   \item To go back, edit, and re-run commands
       
   131   \item But when you close, this is lost
   131 \end{itemize}
   132 \end{itemize}
   132 \end{frame}
   133 \end{frame}
   133 
   134 
   134 \begin{frame}
   135 \begin{frame}
   135 \frametitle{But its impractical..}
   136 \frametitle{But its impractical..}
   136 \begin{itemize}
   137 \begin{itemize}
   137   \item Because we can't always keep running the IPython shell for days
   138   \item We can't keep running IPython for days
   138   \item And lets admit it, its a pain to go back and edit
   139   \item And its a pain to go back and edit
   139 \end{itemize}
   140 \end{itemize}
   140 And the solution is..\\
   141 And the solution is..\\
   141 \begin{center}
   142 \begin{center}
   142 \alert {\typ{Scripts!!}}
   143 \alert {\typ{Scripts!!}}
   143 \end{center}
   144 \end{center}
   144 \end{frame}
   145 \end{frame}
   145 
   146 
   146 \section{Creating and running scripts}
   147 \section{Scripts}
   147 \begin{frame}[fragile]
   148 \begin{frame}[fragile]
   148 \frametitle{Python Scripts}
   149 \frametitle{Python Scripts}
   149 \begin{itemize}
   150 \begin{itemize}
   150 \item Let us now put all the commands used in the review problem into a file. 
   151 \item Put all commands used in review problem into a file. 
   151 \item The following commands of IPython help us do this. 
   152 \item use hist command of IPython.
   152 \end{itemize}
   153 \end{itemize}
   153 \begin{lstlisting}
   154 \begin{lstlisting}
   154   In []: %hist
   155   In []: %hist
   155   In []: %hist -n
   156   In []: %hist -n
   156 \end{lstlisting}
   157 \end{lstlisting}
   167   \item run the file in IPython using \typ{\%run sine_plot.py}\\
   168   \item run the file in IPython using \typ{\%run sine_plot.py}\\
   168   \end{itemize}
   169   \end{itemize}
   169 \end{frame}
   170 \end{frame}
   170 
   171 
   171 \begin{frame}[fragile]
   172 \begin{frame}[fragile]
   172 \frametitle{How often do we plot analytical functions?}
   173 \frametitle{Why would I plot f(x)?}
   173 Plotting experimental data is done more often and also more useful.\\
   174 How often do we plot analytical functions?\\We plot experimental data more.
   174 Let us look at a small example:
       
   175 \begin{lstlisting}
   175 \begin{lstlisting}
   176 In []: x = [0, 1, 2, 3]
   176 In []: x = [0, 1, 2, 3]
   177 
   177 
   178 In []: y = [7, 11, 15, 19]
   178 In []: y = [7, 11, 15, 19]
   179 
   179 
   181 Out[]: [<matplotlib.lines.Line2D object at 0xa73aa8c>]
   181 Out[]: [<matplotlib.lines.Line2D object at 0xa73aa8c>]
   182 \end{lstlisting}
   182 \end{lstlisting}
   183 \end{frame}
   183 \end{frame}
   184 
   184 
   185 \begin{frame}[fragile]
   185 \begin{frame}[fragile]
       
   186 \begin{figure}
       
   187 \includegraphics[width=3.5in]{data/straightline.png}
       
   188 \end{figure}
       
   189 \end{frame}
       
   190 
       
   191 \begin{frame}[fragile]
   186 \frametitle{Plotting points}
   192 \frametitle{Plotting points}
   187 \begin{itemize}
   193 \begin{itemize}
   188 \item What if we want to plot points!
   194 \item What if we want to plot the points!
   189 \end{itemize}
   195 \end{itemize}
   190 \begin{lstlisting}
   196 \begin{lstlisting}
   191   In []: clf()
   197   In []: clf()
   192 
   198 
   193   In []: plot(L, TSq, 'o')
   199   In []: plot(L, TSq, 'o')
   209 \end{itemize}
   215 \end{itemize}
   210 \end{frame}
   216 \end{frame}
   211 
   217 
   212 \section{Lists}
   218 \section{Lists}
   213 \begin{frame}[fragile]
   219 \begin{frame}[fragile]
   214   \frametitle{How to create?}
   220   \frametitle{How to create the data?}
   215 What are \typ{x} and \typ{y} here??\\
   221 What are \typ{x} and \typ{y} here??\\
   216 \begin{center}
   222 \begin{center}
   217 \alert{\typ{lists!!}}
   223 \alert{\typ{lists!!}}
   218 \end{center}
   224 \end{center}
   219 \begin{lstlisting}
   225 \begin{lstlisting}
   231 \end{lstlisting}
   237 \end{lstlisting}
   232 \end{frame}
   238 \end{frame}
   233 
   239 
   234 \begin{frame}[fragile]
   240 \begin{frame}[fragile]
   235   \frametitle{List: Slicing}
   241   \frametitle{List: Slicing}
       
   242   \begin{block}{Remember\ldots}
       
   243 	\kwrd{In []: lst = [1,2,3,4,5]}
       
   244   \end{block}
   236 \alert{\typ{list[initial:final:step]}}
   245 \alert{\typ{list[initial:final:step]}}
   237 \begin{lstlisting}
   246 \begin{lstlisting}
   238 In []: lst[1:3]  # A slice.
   247 In []: lst[1:3]  # A slice.
   239 Out[]: [2, 3]
   248 Out[]: [2, 3]
   240 
   249 
   242 Out[]: [2, 3]
   251 Out[]: [2, 3]
   243 \end{lstlisting}
   252 \end{lstlisting}
   244 \end{frame}
   253 \end{frame}
   245 
   254 
   246 \begin{frame}[fragile]
   255 \begin{frame}[fragile]
   247   \frametitle{List concatenation and list methods}
   256   \frametitle{List operations}
   248 \begin{lstlisting}
   257 \begin{lstlisting}
   249 In []: anthrlst = [6,7,8,9]
   258 In []: anthrlst = [6,7,8,9]
   250 In []: lnglst = lst + anthrlst
   259 In []: lnglst = lst + anthrlst
   251 
   260 
   252 In []: lnglst
   261 In []: lnglst
   316 \end{lstlisting}
   325 \end{lstlisting}
   317 This gives the list \kwrd{TSq} which is the list of squares of T values.
   326 This gives the list \kwrd{TSq} which is the list of squares of T values.
   318 \end{frame}
   327 \end{frame}
   319 
   328 
   320 \begin{frame}[fragile]
   329 \begin{frame}[fragile]
   321 \frametitle{\texttt{for}}
   330 \frametitle{More of \texttt{for}}
   322 \begin{itemize}
   331 \begin{itemize}
   323 \item Used to iterate over lists
   332 \item Used to iterate over lists
   324 \item Let us look at another example.
   333 \item Let us look at another example.
   325 \end{itemize}
   334 \end{itemize}
   326 \begin{lstlisting}
   335 \begin{lstlisting}