Many different disciplines, Physics or Economics, for instance, require displaying multiple graphs at once, usually one on top of each other in order to demonstrate how some shock or event impacts different variables. How could this be done in Manim?
Asked
Active
Viewed 2,285 times
1 Answers
8
First of all, let's paste the solution's code.
class PlotTwoGraphsAtOnce(GraphScene):
CONFIG = {
"y_max" : 40,
"y_min" : 0,
"x_max" : 7,
"x_min" : 0,
"y_tick_frequency" : 10,
"x_tick_frequency" : 1,
"x_axis_width": 6,
"y_axis_height": 3,
"axes_color" : GRAY,
}
def construct(self):
self.graph_origin = -0.5 * DOWN + 3 * LEFT
self.setup_axes(animate=True)
graph_up = self.get_graph(lambda x : x**2,
color = GOLD_A,
x_min = 0,
x_max = 3
)
f1 = TexMobject(r"f(x) = {x}^2", color = GOLD_A)
f1.scale(0.7)
label_coord1 = self.input_to_graph_point(3,graph_up)
f1.next_to(label_coord1,RIGHT+UP)
self.graph_origin = 3.5 * DOWN + 3 * LEFT
self.setup_axes(animate=True)
graph_down = self.get_graph(lambda x : x**3,
color = BLUE_D,
x_min = 0,
x_max = 3
)
graphs=VGroup(graph_up,graph_down)
f2 = TexMobject(r"f(x) = {x}^3", color = BLUE_D)
f2.scale(0.7)
label_coord2 = self.input_to_graph_point(3,graph_up)
f2.next_to(label_coord2,RIGHT+UP)
self.play(
ShowCreation(graphs),
run_time = 2,
)
self.play(ShowCreation(f1), ShowCreation(f2))
self.wait(3)
And here's a visual preview of the final result.
For the implementation of this solution I took inspiration from this answer.

shannontesla
- 885
- 1
- 8
- 27
-
How could I draw the two curves simultaneously instead of one after the other? – blindeyes Sep 06 '22 at 07:48
-
Replying to my own question above, just need to not play them as a VGroup, i.e., replace ShowCreation(graphs) with ShowCreation(graph_up), ShowCreation(graph_down) – blindeyes Sep 06 '22 at 08:04