|
5 | 5 | # fonts. After all, if we were slaves to MATLAB , we wouldn't be
|
6 | 6 | # using python!
|
7 | 7 |
|
8 |
| -from pylab import * |
| 8 | +import matplotlib.pyplot as plt |
| 9 | +import numpy as np |
9 | 10 |
|
10 | 11 |
|
11 | 12 | def f(t):
|
12 |
| - s1 = sin(2*pi*t) |
13 |
| - e1 = exp(-t) |
14 |
| - return multiply(s1, e1) |
15 |
| - |
16 |
| -t1 = arange(0.0, 5.0, 0.1) |
17 |
| -t2 = arange(0.0, 5.0, 0.02) |
| 13 | + s1 = np.sin(2*np.pi*t) |
| 14 | + e1 = np.exp(-t) |
| 15 | + return np.multiply(s1, e1) |
18 | 16 |
|
| 17 | +t1 = np.arange(0.0, 5.0, 0.1) |
| 18 | +t2 = np.arange(0.0, 5.0, 0.02) |
19 | 19 |
|
20 | 20 | fig, ax = plt.subplots()
|
21 |
| -plot(t1, f(t1), 'bo', t2, f(t2), 'k') |
22 |
| -text(3.0, 0.6, 'f(t) = exp(-t) sin(2 pi t)') |
23 |
| -ttext = title('Fun with text!') |
24 |
| -ytext = ylabel('Damped oscillation') |
25 |
| -xtext = xlabel('time (s)') |
26 |
| - |
27 |
| -setp(ttext, size='large', color='r', style='italic') |
28 |
| -setp(xtext, size='medium', name=['Courier', 'Bitstream Vera Sans Mono'], |
| 21 | +plt.plot(t1, f(t1), 'bo', t2, f(t2), 'k') |
| 22 | +plt.text(3.0, 0.6, 'f(t) = exp(-t) sin(2 pi t)') |
| 23 | +ttext = plt.title('Fun with text!') |
| 24 | +ytext = plt.ylabel('Damped oscillation') |
| 25 | +xtext = plt.xlabel('time (s)') |
| 26 | + |
| 27 | +plt.setp(ttext, size='large', color='r', style='italic') |
| 28 | +plt.setp(xtext, size='medium', name=['Courier', 'Bitstream Vera Sans Mono'], |
29 | 29 | weight='bold', color='g')
|
30 |
| -setp(ytext, size='medium', name=['Helvetica', 'Bitstream Vera Sans'], |
| 30 | +plt.setp(ytext, size='medium', name=['Helvetica', 'Bitstream Vera Sans'], |
31 | 31 | weight='light', color='b')
|
32 |
| -show() |
| 32 | +plt.show() |
0 commit comments