forked from 3b1b/manim
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEB_plot_2d.py
More file actions
100 lines (92 loc) · 2.73 KB
/
EB_plot_2d.py
File metadata and controls
100 lines (92 loc) · 2.73 KB
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
from manimlib.imports import *
class Plot1(GraphScene):
CONFIG = {
"y_max": 50,
"y_min": 0,
"x_max": 7,
"x_min": 0,
"y_tick_frequency": 5,
"x_tick_frequency": 0.5,
"axes_color": BLUE,
"y_labeled_nums": range(0, 60, 10),
"x_labeled_nums": list(np.arange(2, 7.0 + 0.5, 0.5)),
"x_label_decimal": 1,
"y_label_direction": RIGHT,
"x_label_direction": UP,
"y_label_decimal": 3
}
def construct(self):
self.setup_axes(animate=True)
graph = self.get_graph(lambda x: x**2, color=GREEN, x_min=2, x_max=4)
self.play(ShowCreation(graph), run_time=2)
self.wait()
class Plot1v2(GraphScene):
CONFIG = {
"y_max": 50,
"y_min": 0,
"x_max": 7,
"x_min": 0,
"y_tick_frequency": 5,
"x_tick_frequency": 1,
"axes_color": BLUE,
"graph_origin": np.array((0, 0, 0))
}
def construct(self):
self.setup_axes(animate=True)
graph = self.get_graph(lambda x: x**2, color=GREEN, x_min=2, x_max=4)
self.play(ShowCreation(graph), run_time=2)
self.wait()
class Plot2(GraphScene):
CONFIG = {
"y_max" : 50,
"y_min" : 0,
"x_max" : 7,
"x_min" : 0,
"y_tick_frequency" : 5,
"axes_color" : BLUE,
"x_axis_label" : "$t$",
"y_axis_label" : "$f(t)$",
}
def construct(self):
self.setup_axes()
graph = self.get_graph(lambda x : x**2, color = GREEN)
self.play(
ShowCreation(graph),
run_time = 2
)
self.wait()
def setup_axes(self):
# Add this line
GraphScene.setup_axes(self)
# Parametters of labels
# For x
init_label_x = 2
end_label_x = 7
step_x = 1
# For y
init_label_y = 20
end_label_y = 50
step_y = 5
# Position of labels
# For x
self.x_axis.label_direction = DOWN #DOWN is default
# For y
self.y_axis.label_direction = LEFT
# Add labels to graph
# For x
self.x_axis.add_numbers(*range(
init_label_x,
end_label_x+step_x,
step_x
))
# For y
self.y_axis.add_numbers(*range(
init_label_y,
end_label_y+step_y,
step_y
))
# Add Animation
self.play(
ShowCreation(self.x_axis),
ShowCreation(self.y_axis)
)