-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot.py
executable file
·87 lines (67 loc) · 2.38 KB
/
plot.py
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
#!/usr/bin/env python3
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import os
import sys
fig = plt.figure()
def f(x):
return pow(2, -10 * x**2) + x**3
min_x = -1.0
max_x = 1.0
x_point = 0.5
width = 0.2
x = np.arange(min_x, max_x, 0.01)
y = f(x)
x2 = np.arange(x_point-0.1, x_point+0.1, 0.01)
y2 = f(x2)
graph_color = 'blue'
def make_frame(label):
ax = plt.axes(label=label)
ax.set_title(label)
ax.plot(x, y, alpha=0)
return ax
def fileName(number):
return "continuous{}.png".format(number)
def generate_frame0():
ax = make_frame("Take an arbitrary function")
ax.plot(x, y, color=graph_color)
plt.savefig(fileName(0))
def generate_frame1():
ax = make_frame("Its infinitely small fragment")
ax.plot(x, y, alpha=0)
ax.plot(x2, y2, color=graph_color)
plt.savefig(fileName(1))
def generate_frame2():
ax = make_frame("Topological transformation\nto have infinitely small width")
ax.plot(x, y, alpha=0)
ax.fill_between(x2, y2-width/2, y2+width/2, color=graph_color)
plt.savefig(fileName(2))
def generate_frame3():
ax = make_frame("...does not differ of")
ax.plot(x, y, alpha=0)
ax.fill_between(x2, [f(x_point)-width/2 for t in x2], [f(x_point)+width/2 for t in x2], color=graph_color)
plt.savefig(fileName(3))
def generate_frame4():
ax = make_frame("Shift to infinitely many x positions.\nThis set is the generalized limit")
ax.plot(x, y, alpha=0)
for i in range(6):
ax.fill_between(x2 + (i-4)*0.3, [f(x_point)-width/2 for t in x2], [f(x_point)+width/2 for t in x2], color=graph_color)
plt.savefig(fileName(4))
def generate_frame5():
ax = make_frame("Its y limit point is the customary limit")
ax.plot(x, y, alpha=0)
for i in range(6):
ax.fill_between(x2 + (i-4)*0.3, [f(x_point)-width/2 for t in x2], [f(x_point)+width/2 for t in x2], color=graph_color)
ax.plot(x, [f(x_point) for t in x], color='red')
plt.savefig(fileName(5))
def generate_frame(number):
h = [generate_frame0, generate_frame1, generate_frame2, generate_frame3, generate_frame4, generate_frame5]
h[number]()
# if os.system("convert -delay 200 -loop 0 frame*.png plot.gif"):
# raise "Cannot execute `convert`."
# if os.system("rm -f frame*.png"):
# raise "Cannot remove temp files."
ids = (int(x) for x in sys.argv[1:])
for id in ids:
generate_frame(id)