|
1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
2 %Tutorial slides on Python. |
|
3 % |
|
4 % Author: FOSSEE |
|
5 % Copyright (c) 2009, FOSSEE, IIT Bombay |
|
6 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
7 |
|
8 \documentclass[14pt,compress]{beamer} |
|
9 %\documentclass[draft]{beamer} |
|
10 %\documentclass[compress,handout]{beamer} |
|
11 %\usepackage{pgfpages} |
|
12 %\pgfpagesuselayout{2 on 1}[a4paper,border shrink=5mm] |
|
13 |
|
14 % Modified from: generic-ornate-15min-45min.de.tex |
|
15 \mode<presentation> |
|
16 { |
|
17 \usetheme{Warsaw} |
|
18 \useoutertheme{infolines} |
|
19 \setbeamercovered{transparent} |
|
20 } |
|
21 |
|
22 \usepackage[english]{babel} |
|
23 \usepackage[latin1]{inputenc} |
|
24 %\usepackage{times} |
|
25 \usepackage[T1]{fontenc} |
|
26 |
|
27 % Taken from Fernando's slides. |
|
28 \usepackage{ae,aecompl} |
|
29 \usepackage{mathpazo,courier,euler} |
|
30 \usepackage[scaled=.95]{helvet} |
|
31 |
|
32 \definecolor{darkgreen}{rgb}{0,0.5,0} |
|
33 |
|
34 \usepackage{listings} |
|
35 \lstset{language=Python, |
|
36 basicstyle=\ttfamily\bfseries, |
|
37 commentstyle=\color{red}\itshape, |
|
38 stringstyle=\color{darkgreen}, |
|
39 showstringspaces=false, |
|
40 keywordstyle=\color{blue}\bfseries} |
|
41 |
|
42 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
43 % Macros |
|
44 \setbeamercolor{emphbar}{bg=blue!20, fg=black} |
|
45 \newcommand{\emphbar}[1] |
|
46 {\begin{beamercolorbox}[rounded=true]{emphbar} |
|
47 {#1} |
|
48 \end{beamercolorbox} |
|
49 } |
|
50 \newcounter{time} |
|
51 \setcounter{time}{0} |
|
52 \newcommand{\inctime}[1]{\addtocounter{time}{#1}{\tiny \thetime\ m}} |
|
53 |
|
54 \newcommand{\typ}[1]{\lstinline{#1}} |
|
55 |
|
56 \newcommand{\kwrd}[1]{ \texttt{\textbf{\color{blue}{#1}}} } |
|
57 |
|
58 %%% This is from Fernando's setup. |
|
59 % \usepackage{color} |
|
60 % \definecolor{orange}{cmyk}{0,0.4,0.8,0.2} |
|
61 % % Use and configure listings package for nicely formatted code |
|
62 % \usepackage{listings} |
|
63 % \lstset{ |
|
64 % language=Python, |
|
65 % basicstyle=\small\ttfamily, |
|
66 % commentstyle=\ttfamily\color{blue}, |
|
67 % stringstyle=\ttfamily\color{orange}, |
|
68 % showstringspaces=false, |
|
69 % breaklines=true, |
|
70 % postbreak = \space\dots |
|
71 % } |
|
72 |
|
73 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
74 % Title page |
|
75 \title[Basic Plotting]{Python for Scientific Computing : Basic Plotting} |
|
76 |
|
77 \author[FOSSEE] {FOSSEE} |
|
78 |
|
79 \institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay} |
|
80 \date{} |
|
81 %% \date[] {7 November, 2009\\Day 1, Session 1} |
|
82 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
83 |
|
84 %\pgfdeclareimage[height=0.75cm]{iitmlogo}{iitmlogo} |
|
85 %\logo{\pgfuseimage{iitmlogo}} |
|
86 |
|
87 |
|
88 %% Delete this, if you do not want the table of contents to pop up at |
|
89 %% the beginning of each subsection: |
|
90 %% \AtBeginSubsection[] |
|
91 %% { |
|
92 %% \begin{frame}<beamer> |
|
93 %% \frametitle{Outline} |
|
94 %% \tableofcontents[currentsection,currentsubsection] |
|
95 %% \end{frame} |
|
96 %% } |
|
97 |
|
98 %% \AtBeginSection[] |
|
99 %% { |
|
100 %% \begin{frame}<beamer> |
|
101 %% \frametitle{Outline} |
|
102 %% \tableofcontents[currentsection,currentsubsection] |
|
103 %% \end{frame} |
|
104 %% } |
|
105 |
|
106 % If you wish to uncover everything in a step-wise fashion, uncomment |
|
107 % the following command: |
|
108 %\beamerdefaultoverlayspecification{<+->} |
|
109 |
|
110 %%\includeonlyframes{current,current1,current2,current3,current4,current5,current6} |
|
111 |
|
112 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
113 % DOCUMENT STARTS |
|
114 \begin{document} |
|
115 |
|
116 \begin{frame} |
|
117 \maketitle |
|
118 \end{frame} |
|
119 |
|
120 %% \begin{frame} |
|
121 %% \frametitle{Outline} |
|
122 %% \tableofcontents |
|
123 %% % You might wish to add the option [pausesections] |
|
124 %% \end{frame} |
|
125 |
|
126 %% \begin{frame} |
|
127 %% \frametitle{Workshop Schedule: Day 1} |
|
128 %% \begin{description} |
|
129 %% \item[Session 1] Sat 09:00--10:00 |
|
130 %% \item[Session 2] Sat 10:05--11:05 |
|
131 %% \item[Session 3] Sat 11:20--12:20 |
|
132 %% \item[Session 4] Sat 12:25--13:25 |
|
133 %% \item[Quiz 1] Sat 14:25--14:40 |
|
134 %% \item[Session 5] Sat 14:40--15:25 |
|
135 %% \item[Session 6] Sat 15:40--16:40 |
|
136 %% \item[Quiz 2] Sat 16:45--17:00 |
|
137 %% \end{description} |
|
138 %% \end{frame} |
|
139 |
|
140 %% \begin{frame} |
|
141 %% \frametitle{Workshop Schedule: Day 2} |
|
142 %% \begin{description} |
|
143 %% \item[Session 1] Sun 09:00--10:00 |
|
144 %% \item[Session 2] Sun 10:05--11:05 |
|
145 %% \item[Session 3] Sun 11:20--12:20 |
|
146 %% \item[Session 4] Sun 12:25--13:25 |
|
147 %% \item[Quiz 1] Sun 14:25--14:40 |
|
148 %% \item[Session 5] Sun 14:40--15:25 |
|
149 %% \item[Session 6] Sun 15:40--16:40 |
|
150 %% \item[Quiz 2] Sun 16:45--17:00 |
|
151 %% \end{description} |
|
152 %% \end{frame} |
|
153 |
|
154 \begin{frame} |
|
155 \frametitle{About the Workshop} |
|
156 \begin{block}{Intended Audience} |
|
157 \begin{itemize} |
|
158 \item Engg., Mathematics and Science teachers. |
|
159 \item Interested students from similar streams. |
|
160 \end{itemize} |
|
161 \end{block} |
|
162 |
|
163 \begin{block}{Goal: Successful participants will be able to} |
|
164 \begin{itemize} |
|
165 \item Use Python as a basic Plotting tool. |
|
166 \item Understand how to use Python as a scripting and problem solving language. |
|
167 |
|
168 \end{itemize} |
|
169 \end{block} |
|
170 \end{frame} |
|
171 |
|
172 \section{Getting started} |
|
173 \begin{frame} |
|
174 \frametitle{Checklist} |
|
175 \begin{itemize} |
|
176 \item IPython |
|
177 \item Pylab |
|
178 %% \item Editor: We recommend scite. |
|
179 %% \item Data files: |
|
180 %% \begin{itemize} |
|
181 %% \item \typ{sslc1.txt} |
|
182 %% \item \typ{pendulum.txt} |
|
183 %% \item \typ{points.txt} |
|
184 %% \item \typ{pos.txt} |
|
185 %% \end{itemize} |
|
186 %% \item Python scripts: |
|
187 %% \begin{itemize} |
|
188 %% \item \typ{sslc_allreg.py} |
|
189 %% \item \typ{sslc_science.py} |
|
190 %% \end{itemize} |
|
191 %% \item Images |
|
192 %% \begin{itemize} |
|
193 %% \item \typ{lena.png} |
|
194 %% \item \typ{smoothing.gif} |
|
195 \end{itemize} |
|
196 %% \end{enumerate} |
|
197 \end{frame} |
|
198 |
|
199 \begin{frame}[fragile] |
|
200 \frametitle{Starting up \ldots} |
|
201 \begin{block}{} |
|
202 \begin{verbatim} |
|
203 $ ipython -pylab |
|
204 \end{verbatim} |
|
205 \end{block} |
|
206 \begin{lstlisting} |
|
207 In []: print "Hello, World!" |
|
208 Hello, World! |
|
209 \end{lstlisting} |
|
210 Exiting |
|
211 \begin{lstlisting} |
|
212 In []: ^D(Ctrl-D) |
|
213 Do you really want to exit([y]/n)? y |
|
214 \end{lstlisting} |
|
215 \end{frame} |
|
216 |
|
217 %% \begin{frame}[fragile] |
|
218 %% \frametitle{Loops} |
|
219 %% Breaking out of loops |
|
220 %% \begin{lstlisting} |
|
221 %% In []: while True: |
|
222 %% ...: print "Hello, World!" |
|
223 %% ...: |
|
224 %% Hello, World! |
|
225 %% Hello, World!^C(Ctrl-C) |
|
226 %% ------------------------------------ |
|
227 %% KeyboardInterrupt |
|
228 |
|
229 %% \end{lstlisting} |
|
230 %% \end{frame} |
|
231 |
|
232 \section{Plotting} |
|
233 |
|
234 \subsection{Drawing plots} |
|
235 \begin{frame}[fragile] |
|
236 \frametitle{First Plot} |
|
237 \begin{columns} |
|
238 \column{0.20\textwidth} |
|
239 \hspace*{-0.12in} |
|
240 \includegraphics[height=1.2in, interpolate=true]{data/firstplot} |
|
241 \column{0.7\textwidth} |
|
242 \begin{block}{} |
|
243 \begin{small} |
|
244 \begin{lstlisting} |
|
245 In []: x=lins<tab> |
|
246 In []: x=linspace( |
|
247 ... : (Ctrl-C) |
|
248 In []: x = linspace(0, 2*pi, 50) |
|
249 In []: plot(x, sin(x)) |
|
250 \end{lstlisting} |
|
251 \end{small} |
|
252 \end{block} |
|
253 \begin{block}{Ipython Feature} |
|
254 \begin{itemize} |
|
255 \item Use Tab for auto-suggestions. |
|
256 \item In []: (Ctrl-C) to get back In[] prompt from ... |
|
257 \end{itemize} |
|
258 \end{block} |
|
259 \end{columns} |
|
260 \end{frame} |
|
261 |
|
262 |
|
263 \begin{frame}[fragile] |
|
264 \frametitle{Function Documentation} |
|
265 \begin {block}{} |
|
266 \begin{lstlisting} |
|
267 In []: linspace? |
|
268 \end{lstlisting} |
|
269 \end{block} |
|
270 \begin{block}{Ipython Feature} |
|
271 \begin{itemize} |
|
272 \item linspace? , ? mark after a function shows its documentation |
|
273 \item q to exit help |
|
274 \end{itemize} |
|
275 \end{block} |
|
276 \end{frame} |
|
277 |
|
278 |
|
279 \begin{frame}[fragile] |
|
280 \frametitle{Walkthrough} |
|
281 \begin{block}{\typ{x = linspace(start, stop, num)} } |
|
282 returns \typ{num} evenly spaced points, in the interval [\typ{start}, \typ{stop}]. |
|
283 \end{block} |
|
284 \begin{lstlisting} |
|
285 x[0] = start |
|
286 x[num - 1] = end |
|
287 \end{lstlisting} |
|
288 \vspace*{.35in} |
|
289 \begin{block}{\typ{plot(x, y)}} |
|
290 plots \typ{x} and \typ{y} using default line style and color |
|
291 \end{block} |
|
292 %\inctime{10} |
|
293 \end{frame} |
|
294 |
|
295 \subsection{Decoration} |
|
296 \begin{frame}[fragile] |
|
297 \frametitle{Adding Labels and title} |
|
298 \begin{columns} |
|
299 \column{0.25\textwidth} |
|
300 \hspace*{-0.45in} |
|
301 \includegraphics[height=2in, interpolate=true]{data/label} |
|
302 \hspace*{0.5in} |
|
303 \column{0.55\textwidth} |
|
304 \begin{block}{} |
|
305 \small |
|
306 \begin{lstlisting} |
|
307 In []: xlabel('x') |
|
308 In []: ylabel('sin(x)') |
|
309 In []: title('Sinusoids') |
|
310 |
|
311 \end{lstlisting} |
|
312 \small |
|
313 % \end{lstlisting} |
|
314 %\typ{xlabel(s)} sets the label of the \typ{x}-axis to \typ{s} |
|
315 |
|
316 % \begin{lstlisting} |
|
317 \end{block} |
|
318 %\typ{ylabel(s)} sets the label of the \typ{y}-axis to \typ{s} |
|
319 \end{columns} |
|
320 \end{frame} |
|
321 |
|
322 %% \begin{frame}[fragile] |
|
323 %% \frametitle{Another example} |
|
324 %% \begin{lstlisting} |
|
325 %% In []: clf() |
|
326 %% \end{lstlisting} |
|
327 %% \emphbar{Clears the plot area.} |
|
328 %% \begin{lstlisting} |
|
329 %% In []: y = linspace(0, 2*pi, 50) |
|
330 %% In []: plot(y, sin(2*y)) |
|
331 %% In []: xlabel('y') |
|
332 %% In []: ylabel('sin(2y)') |
|
333 %% \end{lstlisting} |
|
334 %% \end{frame} |
|
335 |
|
336 \subsection{More decoration} |
|
337 \begin{frame}[fragile] |
|
338 \frametitle{ Legends} |
|
339 \vspace*{-0.15in} |
|
340 % \begin{block}{} |
|
341 % \small |
|
342 \begin{lstlisting} |
|
343 In []: legend(['sin(x)']) |
|
344 \end{lstlisting} |
|
345 % \small |
|
346 % \end{block} |
|
347 \vspace*{-0.1in} |
|
348 \begin{center} |
|
349 \includegraphics[height=2in, interpolate=true]{data/legend} |
|
350 \end{center} |
|
351 \end{frame} |
|
352 |
|
353 \begin{frame}[fragile] |
|
354 \frametitle{Legend Placement} |
|
355 \begin{block}{} |
|
356 \small |
|
357 \begin{lstlisting} |
|
358 In []: legend(['sin(x)'], loc = 'center') |
|
359 \end{lstlisting} |
|
360 \end{block} |
|
361 |
|
362 \begin{columns} |
|
363 \column{0.6\textwidth} |
|
364 \includegraphics[height=1.5in, interpolate=true]{data/position} |
|
365 \column{0.35\textwidth} |
|
366 \vspace{-0.15in} |
|
367 \begin{lstlisting} |
|
368 'best' |
|
369 'right' |
|
370 'center' |
|
371 \end{lstlisting} |
|
372 \end{columns} |
|
373 \begin{block}{Ipython Feature} |
|
374 \begin{itemize} |
|
375 \item Use up arrow and down arrow to get old commands . |
|
376 \end{itemize} |
|
377 \end{block} |
|
378 |
|
379 \end{frame} |
|
380 |
|
381 |
|
382 |
|
383 \begin{frame}[fragile] |
|
384 \frametitle{Annotate a point } |
|
385 |
|
386 \begin{lstlisting} |
|
387 In []:annotate('origin', xy = (0, 0)) |
|
388 \end{lstlisting} |
|
389 |
|
390 |
|
391 \begin{columns} |
|
392 \column{0.6\textwidth} |
|
393 \includegraphics[height=2in, interpolate=true]{data/annotate} |
|
394 \column{0.45\textwidth} |
|
395 \vspace{-0.2in} |
|
396 %% \begin{lstlisting} |
|
397 %% 'best' |
|
398 %% 'right' |
|
399 %% 'center' |
|
400 %% \end{lstlisting} |
|
401 \end{columns} |
|
402 \end{frame} |
|
403 |
|
404 |
|
405 |
|
406 %% \begin{frame}[fragile] |
|
407 %% \frametitle{For arbitrary location} |
|
408 %% \vspace*{-0.1in} |
|
409 %% \begin{lstlisting} |
|
410 %% In []: legend(['sin(2y)'], loc=(.8,.1)) |
|
411 %% \end{lstlisting} |
|
412 %% \emphbar{Specify south-east corner position} |
|
413 %% %\vspace*{-0.2in} |
|
414 %% \begin{center} |
|
415 %% \includegraphics[height=2in, interpolate=true]{data/loc} |
|
416 %% \end{center} |
|
417 %% %\inctime{10} |
|
418 %% \end{frame} |
|
419 |
|
420 \begin{frame}[fragile] |
|
421 \frametitle{Saving \& Closing} |
|
422 \begin{lstlisting} |
|
423 In []: savefig('sin.png') |
|
424 |
|
425 \end{lstlisting} |
|
426 \end{frame} |
|
427 %% \begin{lstlisting} |
|
428 %% In []: clf() |
|
429 %% \end{lstlisting} |
|
430 %% \emphbar{Clears the plot area.} |
|
431 %% \begin{lstlisting} |
|
432 %% In []: y = linspace(0, 2*pi, 50) |
|
433 %% In []: plot(y, sin(2*y)) |
|
434 %% In []: xlabel('y') |
|
435 %% In []: ylabel('sin(2y)') |
|
436 %% \end{lstlisting} |
|
437 %% \end{frame} |
|
438 |
|
439 |
|
440 |
|
441 |
|
442 |
|
443 |
|
444 \section{Multiple plots} |
|
445 \begin{frame}[fragile] |
|
446 \frametitle{Overlaid Plots} |
|
447 \begin{lstlisting} |
|
448 In []: plot(x, cos(x)) |
|
449 In []: xlabel('x') |
|
450 In []: ylabel('f(x)') |
|
451 In []: legend(['sin(x)', 'cos(x)']) |
|
452 In []: clf() |
|
453 \end{lstlisting} |
|
454 \emphbar{By default plots would be overlaid!} |
|
455 \end{frame} |
|
456 |
|
457 \begin{frame}[fragile] |
|
458 \frametitle{Plotting separate figures} |
|
459 \begin{lstlisting} |
|
460 In []: figure(1) |
|
461 In []: plot(x, sin(x)) |
|
462 In []: figure(2) |
|
463 In []: plot(x, cos(x)) |
|
464 In []: figure(1) |
|
465 In []: title('sin(x)') |
|
466 In []: close() |
|
467 In []: close() |
|
468 \end{lstlisting} |
|
469 \end{frame} |
|
470 |
|
471 \begin{frame}[fragile] |
|
472 \frametitle{Showing it better} |
|
473 \vspace{-0.15in} |
|
474 \begin{lstlisting} |
|
475 In []: plot(x, sin(x), 'g' ,linewidth=2) |
|
476 |
|
477 In []: clf() |
|
478 |
|
479 \end{lstlisting} |
|
480 \vspace*{-0.2in} |
|
481 \begin{center} |
|
482 \includegraphics[height=2.2in, interpolate=true]{data/green} |
|
483 \end{center} |
|
484 %\inctime{10} |
|
485 \end{frame} |
|
486 |
|
487 |
|
488 \begin{frame}[fragile] |
|
489 \frametitle{Showing it better , Using Dots } |
|
490 \vspace{-0.15in} |
|
491 \begin{lstlisting} |
|
492 In []: plot(x, sin(x), '.') |
|
493 |
|
494 In []: clf() |
|
495 |
|
496 \end{lstlisting} |
|
497 \vspace*{-0.2in} |
|
498 \begin{center} |
|
499 \includegraphics[height=2.2in, interpolate=true]{data/dash} |
|
500 \end{center} |
|
501 %\inctime{10} |
|
502 \end{frame} |
|
503 |
|
504 |
|
505 |
|
506 |
|
507 |
|
508 %% \begin{frame}[fragile] |
|
509 %% \frametitle{Review Ipython } |
|
510 %% \vspace{-0.15in} |
|
511 %% \begin{lstlisting} |
|
512 %% In []: lins<tab> |
|
513 |
|
514 %% In []: function? |
|
515 %% :q |
|
516 %% (Ctrl-D) |
|
517 %% In []: ^C(Ctrl-C) |
|
518 |
|
519 |
|
520 |
|
521 %% \end{lstlisting} |
|
522 %% %\inctime{10} |
|
523 %% \end{frame} |
|
524 |
|
525 |
|
526 \begin{frame}[fragile] |
|
527 \frametitle{Review Ipython Features } |
|
528 \vspace{-0.1in} |
|
529 \begin{itemize} |
|
530 \item Entering Ipython. |
|
531 \begin{verbatim} |
|
532 $ ipython -pylab |
|
533 \end{verbatim} |
|
534 \item Seeing the documentation . |
|
535 \begin{lstlisting} |
|
536 In []: linspace? |
|
537 \end{lstlisting} |
|
538 \item Quitting the documentation . |
|
539 \begin{lstlisting} |
|
540 :q |
|
541 \end{lstlisting} |
|
542 \item Quitting from the ... prompt. |
|
543 \begin{lstlisting} |
|
544 Ctrl-C |
|
545 \end{lstlisting} |
|
546 \end{itemize} |
|
547 \begin{itemize} |
|
548 \item Quitting Ipython |
|
549 \begin{lstlisting} |
|
550 Ctrl-D |
|
551 \end{lstlisting} |
|
552 \end{itemize} |
|
553 |
|
554 |
|
555 %\inctime{10} |
|
556 \end{frame} |
|
557 |
|
558 \begin{frame}[fragile] |
|
559 \frametitle{Review Plotting } |
|
560 \vspace{-0.15in} |
|
561 \begin{itemize} |
|
562 \item Outputting things. |
|
563 \end{itemize} |
|
564 \begin{lstlisting} |
|
565 In []: print ''hello world'' |
|
566 \end{lstlisting} |
|
567 \begin{itemize} |
|
568 \item Create equally spaced points. |
|
569 \end{itemize} |
|
570 \begin{lstlisting} |
|
571 In []: x=linspace(0,2*pi,50) |
|
572 \end{lstlisting} |
|
573 \begin{itemize} |
|
574 \item Simple Plotting |
|
575 \end{itemize} |
|
576 \begin{lstlisting} |
|
577 In []: plot(x,sin(x),'.',linewidth=2) |
|
578 \end{lstlisting} |
|
579 \end{frame} |
|
580 |
|
581 |
|
582 \begin{frame}[fragile] |
|
583 \frametitle{Review Plotting } |
|
584 \vspace{-0.1in} |
|
585 \begin{itemize} |
|
586 \item label axis |
|
587 \end{itemize} |
|
588 \begin{lstlisting} |
|
589 In []: xlabel('x') |
|
590 \end{lstlisting} |
|
591 \begin{itemize} |
|
592 \item Title The plot |
|
593 \end{itemize} |
|
594 \begin{lstlisting} |
|
595 In []: title('sinusoid') |
|
596 \end{lstlisting} |
|
597 \begin{itemize} |
|
598 \item Place legend at a proper place |
|
599 \end{itemize} |
|
600 \begin{lstlisting} |
|
601 In []: legend(['sin(x)']) |
|
602 \end{lstlisting} |
|
603 \begin{itemize} |
|
604 \item Annotate the plot |
|
605 \end{itemize} |
|
606 \begin{lstlisting} |
|
607 In []:annotate('origin' , xy=(0,0)) |
|
608 \end{lstlisting} |
|
609 %\inctime{10} |
|
610 \end{frame} |
|
611 |
|
612 |
|
613 |
|
614 |
|
615 \begin{frame}[fragile] |
|
616 \frametitle{Review Plotting } |
|
617 \vspace{-0.15in} |
|
618 \begin{itemize} |
|
619 \item Save a plot |
|
620 \end{itemize} |
|
621 \begin{lstlisting} |
|
622 In []:savefig('sine.png') |
|
623 \end{lstlisting} |
|
624 \begin{itemize} |
|
625 \item Managing multiple plots using figure |
|
626 \end{itemize} |
|
627 \begin{lstlisting} |
|
628 In []:figure(1) |
|
629 \end{lstlisting} |
|
630 \begin{itemize} |
|
631 \item Clearing plot |
|
632 \end{itemize} |
|
633 \begin{lstlisting} |
|
634 In []: clf() |
|
635 \end{lstlisting} |
|
636 \begin{itemize} |
|
637 \item Closing plot |
|
638 \end{itemize} |
|
639 \begin{lstlisting} |
|
640 In []: close() |
|
641 \end{lstlisting} |
|
642 |
|
643 %\inctime{10} |
|
644 \end{frame} |
|
645 |
|
646 |
|
647 |
|
648 |
|
649 |
|
650 |
|
651 |
|
652 %% \begin{frame}[fragile] |
|
653 %% \frametitle{Review , Function and Commands } |
|
654 %% \vspace{-0.15in} |
|
655 %% \begin{lstlisting} |
|
656 |
|
657 %% In []: print 'hello world' |
|
658 %% In []: x=linspace(0,2*pi,50) |
|
659 %% In []: plot(x, sin(x), 'g',linewidth=2) |
|
660 %% In []: xlabel('x') |
|
661 %% In []: ylabel('sin(x)') |
|
662 %% In []: title('sinusoid') |
|
663 %% In []: legend(['sin(x)','cos(x)']) |
|
664 %% In []: annotate('origin', xy=(0,0)) |
|
665 %% In []: savefig('sine.png') |
|
666 %% In []: clf() |
|
667 %% In []: figure(1) |
|
668 %% \end{lstlisting} |
|
669 %% %\inctime{10} |
|
670 %% \end{frame} |
|
671 |
|
672 |
|
673 |
|
674 %% \begin{frame}[fragile] |
|
675 %% \frametitle{Annotating} |
|
676 %% \vspace*{-0.15in} |
|
677 %% \begin{lstlisting} |
|
678 %% In []: annotate('local max', xy=(1.5, 1)) |
|
679 %% \end{lstlisting} |
|
680 %% \vspace*{-0.2in} |
|
681 %% \begin{center} |
|
682 %% \includegraphics[height=2in, interpolate=true]{data/annotate} |
|
683 %% \end{center} |
|
684 %% \end{frame} |
|
685 |
|
686 %% \begin{frame}[fragile] |
|
687 %% \frametitle{Axes lengths} |
|
688 %% \emphbar{Get the axes limits} |
|
689 %% \begin{lstlisting} |
|
690 %% In []: xmin, xmax = xlim() |
|
691 %% In []: ymin, ymax = ylim() |
|
692 %% \end{lstlisting} |
|
693 %% \emphbar{Set the axes limits} |
|
694 %% \begin{lstlisting} |
|
695 %% In []: xmax = 2*pi |
|
696 %% In []: xlim(xmin, xmax) |
|
697 %% In []: ylim(ymin-0.2, ymax+0.2) |
|
698 %% \end{lstlisting} |
|
699 %% \end{frame} |
|
700 |
|
701 %% \begin{frame}[fragile] |
|
702 %% \frametitle{Review Problem} |
|
703 %% \begin{enumerate} |
|
704 %% \item Plot x, -x, sin(x), xsin(x) in range $-5\pi$ to $5\pi$ |
|
705 %% \item Add a legend |
|
706 %% \item Annotate the origin |
|
707 %% \item Set axes limits to the range of x |
|
708 %% \end{enumerate} |
|
709 %% \begin{lstlisting} |
|
710 %% In []: x=linspace(-5*pi, 5*pi, 500) |
|
711 %% In []: plot(x, x, 'b') |
|
712 %% In []: plot(x, -x, 'b') |
|
713 %% \end{lstlisting} |
|
714 %% $\vdots$ |
|
715 %% \end{frame} |
|
716 |
|
717 %% \begin{frame}[fragile] |
|
718 %% \frametitle{Review Problem \ldots} |
|
719 %% \begin{lstlisting} |
|
720 %% In []: plot(x, sin(x), 'g', linewidth=2) |
|
721 %% In []: plot(x, x*sin(x), 'r', |
|
722 %% linewidth=3) |
|
723 %% \end{lstlisting} |
|
724 %% \begin{lstlisting} |
|
725 %% In []: legend(['x', '-x', 'sin(x)', |
|
726 %% 'xsin(x)']) |
|
727 %% In []: annotate('origin', xy = (0, 0)) |
|
728 %% In []: xlim(-5*pi, 5*pi) |
|
729 %% In []: ylim(-5*pi, 5*pi) |
|
730 %% \end{lstlisting} |
|
731 %% \end{frame} |
|
732 |
|
733 %% \begin{frame}[fragile] |
|
734 %% \frametitle{Saving Commands} |
|
735 %% Save commands of review problem into file |
|
736 %% \begin{itemize} |
|
737 %% \item Use \typ{\%hist} command of IPython |
|
738 %% \item Identify the required line numbers |
|
739 %% \item Then, use \typ{\%save} command of IPython |
|
740 %% \end{itemize} |
|
741 %% \typ{In []: \%hist}\\ |
|
742 %% \typ{In []: \%save four_plot.py} \alert{\typ{16 18-27}} |
|
743 %% \begin{block}{Careful about errors!} |
|
744 %% \kwrd{\%hist} will contain the errors as well,\\ |
|
745 %% so be careful while selecting line numbers. |
|
746 %% \end{block} |
|
747 %% \end{frame} |
|
748 |
|
749 %% \begin{frame} |
|
750 %% \frametitle{Python Scripts\ldots} |
|
751 %% This is called a Python Script. |
|
752 %% \begin{itemize} |
|
753 %% \item run the script in IPython using \typ{\%run -i four_plot.py}\\ |
|
754 %% \end{itemize} |
|
755 %% \end{frame} |
|
756 |
|
757 %% \begin{frame}[fragile] |
|
758 %% \frametitle{What did we learn?} |
|
759 %% \begin{itemize} |
|
760 %% \item \kwrd{\%hist} |
|
761 %% \item Saving commands to a script |
|
762 %% \item Running a script using \kwrd{\%run -i} |
|
763 %% \item Creating simple plots. |
|
764 %% \item Adding labels and legends. |
|
765 %% \item Annotating plots. |
|
766 %% \item Changing the looks: size, linewidth |
|
767 %% \end{itemize} |
|
768 %% \end{frame} |
|
769 |
|
770 \end{document} |
|
771 |