如何淡出 GraphScene 中的轴?

How to FadeOut the axes in GraphScene?

在 GraphScene 中,使用 setup_axes 设置轴,如何淡出轴以为其他动画准备空间?

在setup_axes之后,我尝试改变graph_origin移动轴,也失败了。

从技术上讲,您可以使用 self.axes 对象来完成:

class Plot(GraphScene):
    CONFIG = {
        "y_max" : 50,
        "y_min" : 0,
        "x_max" : 7,
        "x_min" : 0,
        "y_tick_frequency" : 5, 
        "x_tick_frequency" : 0.5, 
    }
    def construct(self):
        self.setup_axes()
        graph = self.get_graph(lambda x : x**2,  
                                    color = GREEN,
                                    x_min = 0, 
                                    x_max = 7
                                    )
        self.play(
            ShowCreation(graph),
            run_time = 2
        )
        self.wait()
        self.play(FadeOut(self.axes))
        self.wait()

但是,GraphScene 旨在为每个轴使用一次(您可以在轴上创建多个图形,但不能更改轴),如果您要更改它们,请使用 Scene,这里是一个示例:

class Plot2(Scene):
    def construct(self):
        c1 = FunctionGraph(lambda x: 2*np.exp(-2*(x-1)**2))
        c2 = FunctionGraph(lambda x: x**2)
        axes1=Axes(y_min=-3,y_max=3)
        axes2=Axes(y_min=0,y_max=10)
        self.play(ShowCreation(axes1),ShowCreation(c1))
        self.wait()
        self.play(
            ReplacementTransform(axes1,axes2),
            ReplacementTransform(c1,c2)
        )
        self.wait()

但是,如果你想制作一个非常个性化的图表,你将不得不为坐标轴添加更多选项,而坐标轴是使用 NumberLine 创建的。这不是那么容易做到,但您可以使用 manimlib/scene/graph_scene.py 示例来指导您,Axes 代码在 manimlib/mobject/coordinate_systems.py, NumberLine 代码在 manimlib/mobject/number_line.pyFunctionGraph 代码在 manimlib/mobject/functions.py 中以查看更多选项。