1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Tutorial slides on Python.
%
% Author: Prabhu Ramachandran <prabhu at aero.iitb.ac.in>
% Copyright (c) 2005-2009, Prabhu Ramachandran
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\documentclass[14pt,compress]{beamer}
%\documentclass[draft]{beamer}
%\documentclass[compress,handout]{beamer}
%\usepackage{pgfpages}
%\pgfpagesuselayout{2 on 1}[a4paper,border shrink=5mm]
% Modified from: generic-ornate-15min-45min.de.tex
\mode<presentation>
{
\usetheme{Warsaw}
\useoutertheme{split}
\setbeamercovered{transparent}
}
\usepackage[english]{babel}
\usepackage[latin1]{inputenc}
%\usepackage{times}
\usepackage[T1]{fontenc}
% Taken from Fernando's slides.
\usepackage{ae,aecompl}
\usepackage{mathpazo,courier,euler}
\usepackage[scaled=.95]{helvet}
\definecolor{darkgreen}{rgb}{0,0.5,0}
\usepackage{listings}
\lstset{language=Python,
basicstyle=\ttfamily\bfseries,
commentstyle=\color{red}\itshape,
stringstyle=\color{darkgreen},
showstringspaces=false,
keywordstyle=\color{blue}\bfseries}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Macros
\setbeamercolor{emphbar}{bg=blue!20, fg=black}
\newcommand{\emphbar}[1]
{\begin{beamercolorbox}[rounded=true]{emphbar}
{#1}
\end{beamercolorbox}
}
\newcounter{time}
\setcounter{time}{0}
\newcommand{\inctime}[1]{\addtocounter{time}{#1}{\tiny \thetime\ m}}
\newcommand{\typ}[1]{\lstinline{#1}}
\newcommand{\kwrd}[1]{ \texttt{\textbf{\color{blue}{#1}}} }
%%% This is from Fernando's setup.
% \usepackage{color}
% \definecolor{orange}{cmyk}{0,0.4,0.8,0.2}
% % Use and configure listings package for nicely formatted code
% \usepackage{listings}
% \lstset{
% language=Python,
% basicstyle=\small\ttfamily,
% commentstyle=\ttfamily\color{blue},
% stringstyle=\ttfamily\color{orange},
% showstringspaces=false,
% breaklines=true,
% postbreak = \space\dots
% }
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Title page
\title[]{Matrices and Arrays\\ \& \\2D Plotting}
\author[FOSSEE Team] {Asokan Pichai\\Prabhu Ramachandran}
\institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay}
\date[] {11, October 2009}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\pgfdeclareimage[height=0.75cm]{iitmlogo}{iitmlogo}
%\logo{\pgfuseimage{iitmlogo}}
%% Delete this, if you do not want the table of contents to pop up at
%% the beginning of each subsection:
\AtBeginSubsection[]
{
\begin{frame}<beamer>
\frametitle{Outline}
\tableofcontents[currentsection,currentsubsection]
\end{frame}
}
\AtBeginSection[]
{
\begin{frame}<beamer>
\frametitle{Outline}
\tableofcontents[currentsection,currentsubsection]
\end{frame}
}
% If you wish to uncover everything in a step-wise fashion, uncomment
% the following command:
%\beamerdefaultoverlayspecification{<+->}
%\includeonlyframes{current,current1,current2,current3,current4,current5,current6}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% DOCUMENT STARTS
\begin{document}
\begin{frame}
\maketitle
\end{frame}
\begin{frame}
\frametitle{Outline}
\tableofcontents
% You might wish to add the option [pausesections]
\end{frame}
\section{Matrices and Arrays}
\subsection{Basic \typ{numpy} }
\newcommand{\num}{\texttt{numpy}}
\begin{frame}
\frametitle{The \num\ module}
\begin{itemize}
\item Why?
\item What:
\begin{itemize}
\item An efficient and powerful array type for various common data
types
\item Abstracts out the most commonly used standard operations on
arrays
\end{itemize}
\end{itemize}
\end{frame}
\begin{frame}[fragile]
\frametitle{Examples of \num}
\begin{lstlisting}
# Simple array math example
>>> from numpy import *
>>> a = array([1,2,3,4])
>>> b = array([2,3,4,5])
>>> a*2 + b + 1 # Basic math!
array([5, 8, 11, 14])
# Pi and e are defined.
>>> x = linspace(0.0, 10.0, 1000)
>>> x *= 2*pi/10 # inplace.
# apply functions to array.
>>> y = sin(x)
\end{lstlisting}
\inctime{5}
\end{frame}
\begin{frame}
\frametitle{Basic concepts}
\begin{itemize}
\item fixed size (\typ{arr.size});
\item Same type (\typ{arr.dtype}) of data
\item arbitrary dimensionality
\item \typ{arr.shape}: size in each dimension
\item \alert{Note:} \typ{len(arr) != arr.size} in general
\item \alert{Note:} By default array operations are performed
\alert{elementwise}
\end{itemize}
\end{frame}
\begin{frame}[fragile]
\frametitle{More examples of \num}
\vspace*{-8pt}
\begin{lstlisting}
>>> x = array([1., 2, 3, 4])
>>> size(x)
4
>>> x.dtype # What is a.dtype?
dtype('float64')
>>> x.shape
(4,)
>>> print rank(x), x.itemsize
1 8
>>> x[0] = 10
>>> print x[0], x[-1]
10.0 4.0
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]
\frametitle{Multi-dimensional arrays}
\begin{lstlisting}
>>> a = array([[ 0, 1, 2, 3],
... [10,11,12,13]])
>>> a.shape # (rows, columns)
(2, 4)
# Accessing and setting values
>>> a[1,3]
13
>>> a[1,3] = -1
>>> a[1] # The second row
array([10,11,12,-1])
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]
\frametitle{Array math}
\begin{itemize}
\item Basic \alert{elementwise} math (given two arrays \typ{a, b}):
\typ{+, -, *, /, \%}
\item Inplace operators: \typ{a += b}, or \typ{add(a, b, a)} etc.
\item \typ{sum(x, axis=0)},
\typ{product(x, axis=0)},
\typ{dot(a, bp)}
\end{itemize}
\end{frame}
\begin{frame}[fragile]
\frametitle{Array math cont.}
\begin{itemize}
\item Logical operations: \typ{equal (==)}, \typ{not\_equal (!=)},
\typ{less (<)}, \typ{greater (>)} etc.
\item Trig and other functions: \typ{sin(x),}
\typ{arcsin(x), sinh(x),}
\typ{exp(x), sqrt(x)} etc.
\end{itemize}
\inctime{10}
\end{frame}
\subsection{Array Creation \& Slicing, Striding Arrays}
\begin{frame}[fragile]
\frametitle{Array creation functions}
\begin {block}{\typ{array(object, dtype=None, ...)}}
\begin{lstlisting}
>>> array( [2,3,4] )
array([2, 3, 4])
\end{lstlisting}
\end {block}
\begin{block}{\typ{linspace(start, stop, num=50, ...)}}
\begin{lstlisting}
>>> linspace( 0, 2, 4 )
array([0.,0.6666667,1.3333333,2.])
\end{lstlisting}
\end{block}
\begin{itemize}
\item also try \typ{arange} command
\end{itemize}
\end{frame}
\begin{frame}[fragile]
\frametitle{Array creation functions cont.}
\begin{itemize}
\item \typ{ones(shape, dtype=None, ...)}
\begin{lstlisting}
>>>ones([2,2])
array([[ 1., 1.],
[ 1., 1.]])
\end{lstlisting}
\item \typ{identity(n)}
\item \typ{ones\_like(x)}
\begin{lstlisting}
>>>a = array([[1,2,3],[4,5,6]])
>>>ones_like(a)
array([[1, 1, 1],
[1, 1, 1]])
\end{lstlisting}
\item check out \typ{zeros, zeros\_like, empty}
\end{itemize}
\end{frame}
\begin{frame}[fragile]
\frametitle{Slicing arrays}
\begin{lstlisting}
>>> a = array([[1,2,3], [4,5,6],
[7,8,9]])
>>> a[0,1:3]
array([2, 3])
>>> a[1:,1:]
array([[5, 6],
[8, 9]])
>>> a[:,2]
array([3, 6, 9])
>>> a[...,2]
array([3, 6, 9])
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]
\frametitle{Striding arrays}
\begin{lstlisting}
>>> a[0::2,0::2]
array([[1, 3],
[7, 9]])
# Slices are references to the
# same memory!
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]
\frametitle{Random Numbers}
\begin{lstlisting}
>>> np.random.rand(3,2)
array([[ 0.96276665, 0.77174861],
[ 0.35138557, 0.61462271],
[ 0.16789255, 0.43848811]])
>>> np.random.randint(1,100)
42
\end{lstlisting}
\inctime{15}
\end{frame}
\begin{frame}[fragile]
\frametitle{Problem Set}
\begin{lstlisting}
>>> from scipy import misc
>>> A=misc.imread(name)
>>> misc.imshow(A)
\end{lstlisting}
\begin{enumerate}
\item Convert an RGB image to Grayscale. $ Y = 0.5R + 0.25G + 0.25B $
\item Scale the image to 50\%
\item Introduce some random noise
\item Smooth the image using a mean filter
\\\small{Take the mean of all the neighbouring elements}
\\\small{How fast can you do it?}
\end{enumerate}
\inctime{15}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{2D Plotting}
\subsection{Getting Started}
\begin{frame}
{IPython's \typ{pylab} mode}
\begin{block}{Immediate use:}
\typ{\$ ipython -pylab}
\end{block}
\begin{itemize}
\item \typ{pylab}: convenient 2D plotting interface to MPL
\item Imports all of pylab for you!
\item Allows for interactive plotting
\end{itemize}
\end{frame}
\begin{frame}[fragile]
\frametitle{Basic 2D plotting}
\begin{lstlisting}
>>> x = linspace(0, 2*pi, 1000)
>>> plot(x, sin(x))
>>> plot(x, sin(x), 'ro')
>>> xlabel(r'$\chi$', color='g')
# LaTeX markup!
>>> ylabel(r'sin($\chi$)', color='r')
>>> title('Simple figure', fontsize=20)
>>> savefig('/tmp/test.eps')
\end{lstlisting}
\begin{itemize}
\item Also: PNG, PDF, PS, EPS, SVG, PDF
\end{itemize}
\inctime{5}
\end{frame}
\subsection{Plots - Lines, Labels and Legends}
\begin{frame}[fragile]
\frametitle{Tweaking plots}
\begin{lstlisting}
# Set properties of objects:
>>> l, = plot(x, sin(x))
# Why "l,"?
>>> setp(l, linewidth=2.0, color='r')
>>> l.set_linewidth(2.0)
>>> draw() # Redraw.
>>> setp(l) # Print properties.
>>> clf() # Clear figure.
>>> close() # Close figure.
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]
\frametitle{Working with text \ldots}
%\begin{itemize}
% \item We already saw LaTeX markup support!
%\end{itemize}
\begin{lstlisting}
>>> w = arange(-2,2,.1)
>>> plot(w,exp(-(w*w))*cos)
>>> ylabel('$f(\omega)$')
>>> xlabel('$\omega$')
>>> title(r"$f(\omega)=e^{-\omega^2}
cos({\omega^2})$")
>>> annotate('maxima',xy=(0, 1),
xytext=(1, 0.8),
arrowprops=dict(
facecolor='black',
shrink=0.05))
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]
\frametitle{Legends}
\begin{lstlisting}
>>> x = linspace(0, 2*pi, 1000)
>>> plot(x, cos(5*x), 'r--',
label='cosine')
>>> plot(x, sin(5*x), 'g--',
label='sine')
>>> legend()
# Or use:
>>> legend(['cosine', 'sine'])
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]
\frametitle{Multiple figures}
\begin{lstlisting}
>>> figure(1)
>>> plot(x, sin(x))
>>> figure(2)
>>> plot(x, tanh(x))
>>> figure(1)
>>> title('Easy as 1,2,3')
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]
\frametitle{Note: \typ{pylab} in Python scripts}
\begin{lstlisting}
import pylab
x = pylab.linspace(0, 20, 1000)
pylab.plot(x, pylab.sin(x))
# Can also use:
from pylab import linspace, sin, plot
\end{lstlisting}
\inctime{5}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Types of Plots}
\begin{frame}[fragile]
\frametitle{X-Y plot}
\begin{columns}
\column{0.5\textwidth}
\hspace*{-0.5in}
\includegraphics[height=2in, interpolate=true]{data/xyplot}
\column{0.45\textwidth}
\begin{block}{Example code}
\tiny
\begin{lstlisting}
t1 = arange(0.0, 5.0, 0.1)
t2 = arange(0.0, 5.0, 0.02)
t3 = arange(0.0, 2.0, 0.01)
subplot(211)
plot(t1, cos(2*pi*t1)*exp(-t1), 'bo',
t2, cos(2*pi*t2)*exp(-t2), 'k')
grid(True)
title('A tale of 2 subplots')
ylabel('Damped')
subplot(212)
plot(t3, cos(2*pi*t3), 'r--')
grid(True)
xlabel('time (s)')
ylabel('Undamped')
\end{lstlisting}
\end{block}
\end{columns}
\end{frame}
\begin{frame}[fragile] \frametitle{Semi-log and log-log plots}
\begin{columns}
\column{0.5\textwidth}
\hspace*{-0.5in}
\includegraphics[height=2in, interpolate=true]{data/log}
\column{0.45\textwidth}
\begin{block}{Example code}
\tiny
\begin{lstlisting}
dt = 0.01
t = arange(dt, 20.0, dt)
subplot(311)
semilogy(t, exp(-t/5.0))
ylabel('semilogy')
grid(True)
subplot(312)
semilogx(t, sin(2*pi*t))
ylabel('semilogx')
grid(True)
# minor grid on too
gca().xaxis.grid(True, which='minor')
subplot(313)
loglog(t, 20*exp(-t/10.0), basex=4)
grid(True)
ylabel('loglog base 4 on x')
\end{lstlisting}
\end{block}
\end{columns}
\end{frame}
\begin{frame}[fragile] \frametitle{Errorbar}
\begin{columns}
\column{0.5\textwidth}
\hspace*{-0.5in}
\includegraphics[height=2in, interpolate=true]{data/errorbar}
\column{0.45\textwidth}
\begin{block}{Example code}
\tiny
\begin{lstlisting}
t = arange(0.1, 4, 0.1)
s = exp(-t)
e = 0.1*abs(randn(len(s)))
f = 0.1*abs(randn(len(s)))
g = 2*e
h = 2*f
errorbar(t, s, [e,g], f, fmt='o')
xlabel('Distance (m)')
ylabel('Height (m)')
title('Mean and standard error '\
'as a function of distance')
\end{lstlisting}
\end{block}
\end{columns}
\end{frame}
\begin{frame}[fragile] \frametitle{Histogram}
\begin{columns}
\column{0.5\textwidth}
\hspace*{-0.5in}
\includegraphics[height=2in, interpolate=true]{data/histogram}
\column{0.45\textwidth}
\begin{block}{Example code}
\tiny
\begin{lstlisting}
mu, sigma = 100, 15
x = mu + sigma*randn(10000)
# the histogram of the data
n, bins, patches = hist(x, 100, normed=1)
# add a 'best fit' line
y = normpdf( bins, mu, sigma)
l = plot(bins, y, 'r--', linewidth=2)
xlim(40, 160)
xlabel('Smarts')
ylabel('P')
title(r'$\rm{IQ:}\/ \mu=100,\/ \sigma=15$')
\end{lstlisting}
\end{block}
\end{columns}
\end{frame}
\begin{frame}[fragile] \frametitle{Bar charts}
\begin{columns}
\column{0.5\textwidth}
\hspace*{-0.5in}
\includegraphics[height=2in, interpolate=true]{data/barchart}
\column{0.45\textwidth}
\begin{block}{Example code}
\tiny
\begin{lstlisting}
N = 5
menMeans = (20, 35, 30, 35, 27)
menStd = ( 2, 3, 4, 1, 2)
# the x locations for the groups
ind = arange(N)
# the width of the bars
width = 0.35
p1 = bar(ind, menMeans, width,
color='r', yerr=menStd)
womenMeans = (25, 32, 34, 20, 25)
womenStd = ( 3, 5, 2, 3, 3)
p2 = bar(ind+width, womenMeans, width,
color='y', yerr=womenStd)
ylabel('Scores')
title('Scores by group and gender')
xticks(ind+width,
('G1', 'G2', 'G3', 'G4', 'G5'))
xlim(-width,len(ind))
yticks(arange(0,41,10))
legend((p1[0], p2[0]),
('Men', 'Women'), shadow=True)
\end{lstlisting}
\end{block}
\end{columns}
\end{frame}
\begin{frame}[fragile] \frametitle{Pie charts}
\begin{columns}
\column{0.5\textwidth}
\hspace*{-0.4in}
\includegraphics[height=2.0in, interpolate=true]{data/piechart}
\column{0.45\textwidth}
\begin{block}{Example code}
\tiny
\begin{lstlisting}
# make a square figure and axes
figure(1, figsize=(8,8))
ax = axes([0.1, 0.1, 0.8, 0.8])
labels = 'Frogs', 'Hogs', 'Dogs', 'Logs'
fracs = [15,30,45, 10]
explode=(0, 0.05, 0, 0)
pie(fracs, explode=explode, labels=labels,
autopct='%1.1f%%', shadow=True)
title('Raining Hogs and Dogs',
bbox={'facecolor':'0.8', 'pad':5})
\end{lstlisting}
\end{block}
\end{columns}
\end{frame}
\begin{frame}[fragile] \frametitle{Scatter plots}
\begin{columns}
\column{0.5\textwidth}
\hspace*{-0.4in}
\includegraphics[height=2in, interpolate=true]{data/scatter}
\column{0.45\textwidth}
\begin{block}{Example code}
\tiny
\begin{lstlisting}
N = 30
x = 0.9*rand(N)
y = 0.9*rand(N)
# 0 to 10 point radiuses
area = pi*(10 * rand(N))**2
volume = 400 + rand(N)*450
scatter(x,y,s=area, marker='o', c=volume,
alpha=0.75)
xlabel(r'$\Delta_i$', size='x-large')
ylabel(r'$\Delta_{i+1}$', size='x-large')
title(r'Volume and percent change')
grid(True)
colorbar()
savefig('scatter')
\end{lstlisting}
\end{block}
\end{columns}
\end{frame}
\begin{frame}[fragile] \frametitle{Polar}
\begin{columns}
\column{0.5\textwidth}
\hspace*{-0.5in}
\includegraphics[height=2in, interpolate=true]{data/polar}
\column{0.45\textwidth}
\begin{block}{Example code}
\tiny
\begin{lstlisting}
figure(figsize=(8,8))
ax = axes([0.1, 0.1, 0.8, 0.8],
polar=True,
axisbg='#d5de9c')
r = arange(0,1,0.001)
theta = 2*2*pi*r
polar(theta, r, color='#ee8d18', lw=3)
# the radius of the grid labels
setp(ax.thetagridlabels, y=1.075)
title(r'$\theta=4\pi r$', fontsize=20)
\end{lstlisting}
\end{block}
\end{columns}
\end{frame}
\begin{frame}[fragile] \frametitle{Contours}
\begin{columns}
\column{0.45\textwidth}
\hspace*{-0.5in}
\includegraphics[height=2in, interpolate=true]{data/contour}
\column{0.525\textwidth}
\begin{block}{Example code}
\tiny
\begin{lstlisting}
x = arange(-3.0, 3.0, 0.025)
y = arange(-2.0, 2.0, 0.025)
X, Y = meshgrid(x, y)
Z1 = bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
Z2 = bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
# difference of Gaussians
Z = 10.0 * (Z2 - Z1)
im = imshow(Z, interpolation='bilinear',
origin='lower',
cmap=cm.gray, extent=(-3,3,-2,2))
levels = arange(-1.2, 1.6, 0.2)
# label every second level
clabel(CS, levels[1::2], inline=1,
fmt='%1.1f', fontsize=14)
CS = contour(Z, levels,
origin='lower',
linewidths=2,
extent=(-3,3,-2,2))
# make a colorbar for the contour lines
CB = colorbar(CS, shrink=0.8, extend='both')
title('Lines with colorbar')
hot(); flag()
\end{lstlisting}
\end{block}
\end{columns}
\end{frame}
\begin{frame}[fragile] \frametitle{Velocity vectors}
\begin{columns}
\column{0.5\textwidth}
\hspace*{-0.5in}
\includegraphics[height=2in, interpolate=true]{data/quiver}
\column{0.45\textwidth}
\begin{block}{Example code}
\tiny
\begin{lstlisting}
X,Y = meshgrid(arange(0,2*pi,.2),
arange(0,2*pi,.2) )
U = cos(X)
V = sin(Y)
Q = quiver(X[::3, ::3], Y[::3, ::3],
U[::3, ::3], V[::3, ::3],
color='r', units='x',
linewidths=(2,),
edgecolors=('k'),
headaxislength=5 )
qk = quiverkey(Q, 0.5, 0.03, 1, '1 m/s',
fontproperties=
{'weight': 'bold'})
axis([-1, 7, -1, 7])
title('triangular head; scale '\
'with x view; black edges')
\end{lstlisting}
\end{block}
\end{columns}
\end{frame}
\begin{frame}[fragile] \frametitle{Maps}
\includegraphics[height=2.3in, interpolate=true]{data/plotmap}
\begin{center}
\tiny
For details see \url{http://matplotlib.sourceforge.net/screenshots/plotmap.py}
\end{center}
\inctime{5}
\end{frame}
\begin{frame}
\frametitle{More information}
\begin{itemize}
\item More information here: \url{http://matplotlib.sf.net}
\item \url{http://matplotlib.sf.net/tutorial.html}
\item \url{http://matplotlib.sf.net/screenshots.html}
\end{itemize}
\end{frame}
\begin{frame}
\frametitle{Problem Set}
\begin{enumerate}
\item Write a function that plots any regular n-gon given \typ{n}.
\item Consider the logistic map, $f(x) = kx(1-x)$, plot it for
$k=2.5, 3.5$ and $4$ in the same plot.
\end{enumerate}
\end{frame}
\begin{frame}[fragile]
\frametitle{Problem Set}
\begin{columns}
\column{0.6\textwidth}
\small{
\begin{enumerate}
\item Consider the iteration $x_{n+1} = f(x_n)$ where $f(x) =
kx(1-x)$. Plot the successive iterates of this process.
\item Plot this using a cobweb plot as follows:
\begin{enumerate}
\item Start at $(x_0, 0)$
\item Draw line to $(x_i, f(x_i))$;
\item Set $x_{i+1} = f(x_i)$
\item Draw line to $(x_i, x_i)$
\item Repeat from 2 for as long as you want
\end{enumerate}
\end{enumerate}}
\column{0.35\textwidth}
\hspace*{-0.5in}
\includegraphics[height=1.6in, interpolate=true]{data/cobweb}
\end{columns}
\inctime{20}
\end{frame}
\end{document}
|