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[] {28 January, 2010\\Day 1, Session 1} |
80 \date[] {12 February, 2010\\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 |
121 %% \tableofcontents |
121 %% \tableofcontents |
122 %% % You might wish to add the option [pausesections] |
122 %% % You might wish to add the option [pausesections] |
123 %% \end{frame} |
123 %% \end{frame} |
124 |
124 |
125 \begin{frame} |
125 \begin{frame} |
|
126 \frametitle{Workshop Schedule: Day 1} |
|
127 \begin{description} |
|
128 \item[Session 1] Fri 14:00--15:00 |
|
129 \item[Session 2] Fri 15:05--16:05 |
|
130 \item[Session 3] Fri 16:10--17:10 |
|
131 \item[Quiz 1] Fri 17:10--17:25 |
|
132 \item[Exercises] Thu 17:30--18:00 |
|
133 \end{description} |
|
134 \end{frame} |
|
135 |
|
136 \begin{frame} |
|
137 \frametitle{Workshop Schedule: Day 2} |
|
138 \begin{description} |
|
139 \item[Session 1] Sat 09:00--10:00 |
|
140 \item[Session 2] Sat 10:05--11:05 |
|
141 \item[Session 3] Sat 11:20--12:20 |
|
142 \item[Quiz 2] Fri 14:25--14:40 |
|
143 \end{description} |
|
144 \end{frame} |
|
145 |
|
146 \begin{frame} |
|
147 \frametitle{Workshop Schedule: Day 3} |
|
148 \begin{description} |
|
149 \item[Session 1] Sun 09:00--10:00 |
|
150 \item[Session 2] Sun 10:05--11:05 |
|
151 \item[Session 3] Sun 11:20--12:20 |
|
152 \item[Quiz 3] Sun 12:20--12:30 |
|
153 \item[Exercises] Sun 12:30--13:00 |
|
154 \end{description} |
|
155 \end{frame} |
|
156 |
|
157 \section{Checklist} |
|
158 \begin{frame} |
|
159 \frametitle{Checklist} |
|
160 \begin{enumerate} |
|
161 \item IPython |
|
162 \item Editor |
|
163 \item Data files: |
|
164 \begin{itemize} |
|
165 \item \typ{sslc1.txt} |
|
166 \item \typ{pendulum.txt} |
|
167 \item \typ{points.txt} |
|
168 \item \typ{pos.txt} |
|
169 \item \typ{holmes.txt} |
|
170 \end{itemize} |
|
171 \item Python scripts: |
|
172 \begin{itemize} |
|
173 \item \typ{sslc_allreg.py} |
|
174 \item \typ{sslc_science.py} |
|
175 \end{itemize} |
|
176 \item Images |
|
177 \begin{itemize} |
|
178 \item \typ{lena.png} |
|
179 \item \typ{smoothing.gif} |
|
180 \end{itemize} |
|
181 \end{enumerate} |
|
182 \end{frame} |
|
183 |
|
184 \begin{frame} |
126 \frametitle{About the Workshop} |
185 \frametitle{About the Workshop} |
127 \begin{block}{Intended Audience} |
186 \begin{block}{Intended Audience} |
128 \begin{itemize} |
187 \begin{itemize} |
129 \item Engg., Mathematics and Science teachers. |
188 \item Engg., Mathematics and Science teachers. |
130 \item Interested students from similar streams. |
189 \item Interested students from similar streams. |
136 \item Use Python as plotting, computational tool. |
195 \item Use Python as plotting, computational tool. |
137 \item Understand how to use Python as a scripting and problem solving language. |
196 \item Understand how to use Python as a scripting and problem solving language. |
138 \item Train students for the same. |
197 \item Train students for the same. |
139 \end{itemize} |
198 \end{itemize} |
140 \end{block} |
199 \end{block} |
|
200 \end{frame} |
|
201 |
|
202 \section{Starting up Ipython} |
|
203 \begin{frame}[fragile] |
|
204 \frametitle{Starting up \ldots} |
|
205 \begin{block}{} |
|
206 \begin{lstlisting} |
|
207 $ ipython -pylab |
|
208 \end{lstlisting} %$ |
|
209 \end{block} |
|
210 \begin{lstlisting} |
|
211 In []: print "Hello, World!" |
|
212 Hello, World! |
|
213 \end{lstlisting} |
|
214 Exiting |
|
215 \begin{lstlisting} |
|
216 In []: ^D(Ctrl-D) |
|
217 Do you really want to exit([y]/n)? y |
|
218 \end{lstlisting} |
|
219 \end{frame} |
|
220 |
|
221 \section{Loops} |
|
222 \begin{frame}[fragile] |
|
223 \frametitle{Loops} |
|
224 Breaking out of loops |
|
225 \begin{lstlisting} |
|
226 In []: while True: |
|
227 ...: print "Hello, World!" |
|
228 ...: |
|
229 Hello, World! |
|
230 Hello, World!^C(Ctrl-C) |
|
231 ------------------------------------ |
|
232 KeyboardInterrupt |
|
233 \end{lstlisting} |
141 \end{frame} |
234 \end{frame} |
142 |
235 |
143 \section{Plotting} |
236 \section{Plotting} |
144 \subsection{Drawing plots} |
237 \subsection{Drawing plots} |
145 \begin{frame}[fragile] |
238 \begin{frame}[fragile] |
299 In []: clf() |
392 In []: clf() |
300 In []: figure(1) |
393 In []: figure(1) |
301 In []: plot(y, sin(y)) |
394 In []: plot(y, sin(y)) |
302 In []: figure(2) |
395 In []: figure(2) |
303 In []: plot(y, cos(y)) |
396 In []: plot(y, cos(y)) |
|
397 In []: savefig('cosine.png') |
304 In []: figure(1) |
398 In []: figure(1) |
305 In []: title('sin(y)') |
399 In []: title('sin(y)') |
|
400 In []: savefig('sine.png') |
306 In []: close() |
401 In []: close() |
307 In []: close() |
402 In []: close() |
308 \end{lstlisting} |
403 \end{lstlisting} |
309 \end{frame} |
404 \end{frame} |
310 |
405 |
311 \begin{frame}[fragile] |
406 \begin{frame}[fragile] |
312 \frametitle{Showing it better} |
407 \frametitle{Showing it better} |
313 \vspace{-0.15in} |
408 \vspace{-0.15in} |
314 \begin{lstlisting} |
409 \begin{lstlisting} |
315 In []: plot(y, sin(y), 'g') |
410 In []: plot(y, cos(y), 'r') |
316 |
411 |
317 In []: clf() |
412 In []: clf() |
318 In []: plot(y, cos(y), 'r', linewidth=2) |
413 In []: plot(y, sin(y), 'g', linewidth=2) |
319 \end{lstlisting} |
414 \end{lstlisting} |
320 \vspace*{-0.2in} |
415 \vspace*{-0.2in} |
321 \begin{center} |
416 \begin{center} |
322 \includegraphics[height=2.2in, interpolate=true]{data/green} |
417 \includegraphics[height=2.2in, interpolate=true]{data/green} |
323 \end{center} |
418 \end{center} |
343 In []: xmin, xmax = xlim() |
438 In []: xmin, xmax = xlim() |
344 In []: ymin, ymax = ylim() |
439 In []: ymin, ymax = ylim() |
345 \end{lstlisting} |
440 \end{lstlisting} |
346 \emphbar{Set the axes limits} |
441 \emphbar{Set the axes limits} |
347 \begin{lstlisting} |
442 \begin{lstlisting} |
348 In []: xmax = 2*pi |
443 In []: xlim(xmin, 2*pi) |
349 In []: xlim(xmin, xmax) |
|
350 In []: ylim(ymin-0.2, ymax+0.2) |
444 In []: ylim(ymin-0.2, ymax+0.2) |
351 \end{lstlisting} |
445 \end{lstlisting} |
352 \end{frame} |
446 \end{frame} |
353 |
447 |
354 \begin{frame}[fragile] |
448 \begin{frame}[fragile] |
396 |
490 |
397 \begin{frame}[fragile] |
491 \begin{frame}[fragile] |
398 \frametitle{Saving Commands} |
492 \frametitle{Saving Commands} |
399 Save commands of review problem into file |
493 Save commands of review problem into file |
400 \begin{itemize} |
494 \begin{itemize} |
401 \item Use \typ{\%hist} command of IPython (Recall \%\typ{hist} from the previous session) |
495 \item Use \typ{\%hist} command of IPython |
402 \item Identify the required line numbers |
496 \item Identify the required line numbers |
403 \item Then, use \typ{\%save} command of IPython (Recall \%\typ{save} from the previous session) |
497 \item Then, use \typ{\%save} command of IPython |
404 \end{itemize} |
498 \end{itemize} |
405 \typ{In []: \%hist}\\ |
499 \typ{In []: \%hist}\\ |
406 \typ{In []: \%save four_plot.py} \alert{\typ{16 18-27}} |
500 \typ{In []: \%save four_plot.py} \alert{\typ{16 18-27}} |
407 \begin{block}{Careful about errors!} |
501 \begin{block}{Careful about errors!} |
408 \kwrd{\%hist} will contain the errors as well,\\ |
502 \kwrd{\%hist} will contain the errors as well,\\ |
419 \end{frame} |
513 \end{frame} |
420 |
514 |
421 \begin{frame}[fragile] |
515 \begin{frame}[fragile] |
422 \frametitle{What did we learn?} |
516 \frametitle{What did we learn?} |
423 \begin{itemize} |
517 \begin{itemize} |
|
518 \item Starting up IPython |
|
519 \item \kwrd{\%hist} - History of commands |
|
520 \item \kwrd{\%save} - Saving commands |
424 \item Running a script using \kwrd{\%run -i} |
521 \item Running a script using \kwrd{\%run -i} |
425 \item Creating simple plots. |
522 \item Creating simple plots. |
426 \item Adding labels and legends. |
523 \item Adding labels and legends. |
427 \item Annotating plots. |
524 \item Annotating plots. |
428 \item Changing the looks: size, linewidth |
525 \item Changing the looks: size, linewidth |