In [10]:
import numpy as np
% matplotlib inline
from matplotlib import pyplot as plt

In [11]:
x = np.linspace(-100, 100, 10000)
y = x * x
plt.plot(x, y)
plt.xlabel('$x$')
plt.ylabel('$y(x)$')
plt.show()



In [5]:
x = np.linspace(-np.pi, np.pi, 100)
s = np.sin(x)
c = np.cos(x)
sin_curve, cos_curve = plt.plot(x, s, 'r-', x, c, 'b-')
plt.xlabel('$x$')
plt.legend((sin_curve, cos_curve), ('$sin(x)$', '$cos(x)$'))
plt.show()



In [6]:
x = np.linspace(-10, 10, 1000)
s = np.sin(x)
c = np.cos(x[::100])
plt.subplot(2,1,1)
sin_curve, = plt.plot(x, s, 'b-')
plt.legend((sin_curve,), ('$sin(x)$',))
plt.subplot(2,1,2)
cos_curve, = plt.plot(x[::100], c, 'ro')
plt.legend((cos_curve,), ('$cos(x)$',))
plt.xlabel('$x$')
plt.show()



In [8]:
s = np.sin(x)
c = np.cos(x[::100])
plt.subplot(2,1,1)
sin_curve, = plt.plot(x, s, 'b-')
plt.legend((sin_curve,), ('$sin(x)$',))
plt.subplot(2,1,2)
cos_curve, = plt.plot(x[::100], c, 'ro')
plt.legend((cos_curve,), ('$cos(x)$',))
plt.xlabel('$x$')
plt.show()



In [86]:
x = np.linspace(-10,10,100)
gs = gridspec.GridSpec(3,3)
ax1 = plt.subplot(gs[0, :])
ax2 = plt.subplot(gs[1, :-1])
ax3 = plt.subplot(gs[1:, -1])
ax4 = plt.subplot(gs[-1, 0])
ax5 = plt.subplot(gs[-1, -2])

sin_curve, cos_curve = ax1.plot(x, np.sin(x), 'b-', x, np.cos(x), 'ro')
ax1.legend((sin_curve, cos_curve), ('$sin(x)$', '$cos(x)$'))
ax1.set_xlabel('$x$')

ax2.plot(x, np.sin(x) * np.exp(-0.1 * x), 'b-')

exp, = ax3.plot(x, np.exp(x), 'g^')
ax3.legend((exp,), ('$exp(x)$',))
ax3.set_xlabel('$x$')

def myfunc(x):
    if x > 0:
        return 1
    else:
        return 0
vfunc = np.vectorize(myfunc)
ax4.plot(x, vfunc(x), 'b-')

ax5.plot(x, np.sin(x) * np.exp(-0.01 * x*x), 'b-')

plt.tight_layout()
plt.show()



In [13]:
for i in range(1, 101):
    print(i)


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

In [ ]: