Skip to content

Commit 161dc5f

Browse files
committed
# added another example, where a function is defined outside of construct
1 parent c8f66fa commit 161dc5f

File tree

1 file changed

+39
-8
lines changed

1 file changed

+39
-8
lines changed

docs/source/examples/plots_examples.rst

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,23 +49,55 @@ Examples to illustrate the use of GrapheScenes in Manim
4949
for time, dat in enumerate(data):
5050
dot = Dot().move_to(self.coords_to_point(time, dat))
5151
self.add(dot)
52-
self.wait(1)
53-
print(time)
54-
self.wait()
5552

5653
.. manim:: Plot3bGaussian
5754
:quality: medium
5855
:save_last_frame:
5956

6057
class Plot3bGaussian(GraphScene):
58+
global amp
59+
global mu
60+
global sig
61+
amp = 5
62+
mu = 3
63+
sig = 1
64+
65+
def gaussian(self, x):
66+
return amp * np.exp((-1 / 2 * ((x - mu) / sig) ** 2))
67+
6168
def construct(self):
62-
def gaussian(x):
63-
mu=3; sig= 1; amp=5
64-
return amp*np.exp( ( -1/2 * ( (x-mu)/sig)**2 ) )
6569
self.setup_axes()
66-
graph = self.get_graph(gaussian, x_min=-1, x_max=10).set_stroke(width=5)
70+
graph = self.get_graph(self.gaussian, x_min=-1, x_max=10).set_stroke(width=5)
6771
self.add(graph)
6872

73+
.. manim:: Plot3cGaussian
74+
:quality: medium
75+
:save_last_frame:
76+
77+
class Plot3cGaussian(GraphScene):
78+
def construct(self):
79+
def gaussian(x):
80+
amp = 5
81+
mu = 3
82+
sig = 1
83+
return amp * np.exp((-1 / 2 * ((x - mu) / sig) ** 2))
84+
self.setup_axes()
85+
graph = self.get_graph(gaussian, x_min=-1, x_max=10).set_style(stroke_width=5, stroke_color=GREEN)
86+
self.add(graph)
87+
global amp
88+
global mu
89+
global sig
90+
amp = 5
91+
mu = 3
92+
sig = 1
93+
94+
def gaussian(self, x):
95+
return amp * np.exp((-1 / 2 * ((x - mu) / sig) ** 2))
96+
97+
def construct(self):
98+
self.setup_axes()
99+
graph = self.get_graph(self.gaussian, x_min=-1, x_max=10).set_stroke(width=5)
100+
self.a
69101
.. manim:: Plot4SinCos
70102
:quality: medium
71103
:save_last_frame:
@@ -146,7 +178,6 @@ Examples to illustrate the use of GrapheScenes in Manim
146178
def construct(self):
147179
data = [20, 0, 0, -5]
148180
x = [0, 8, 38, 39]
149-
print(x)
150181
self.setup_axes(animate=True)
151182
dot_collection = VGroup()
152183
for time, val in enumerate(data):

0 commit comments

Comments
 (0)