4

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

4

1 回答 1

8

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

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)

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

x**2 和 x**3 显示在两个图表中,一个在另一个顶部

对于这个解决方案的实施,我从这个答案中获得了灵感。

于 2019-11-03T15:00:08.553 回答