一次创建包含多个图形的场景

Creating a scene with multiple graphs at once

许多不同的学科,例如物理学或经济学,需要同时显示多个图表,通常一个在另一个之上,以展示某些冲击或事件如何影响不同的变量。 这怎么可能在 Manim 中完成?

首先,让我们粘贴解决方案的代码。

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)

这是最终结果的视觉预览。

为了实施此解决方案,我从 this 答案中获得灵感。