在 GraphScene 中,使用 setup_axes 设置轴,如何淡出轴为其他动画准备空间?
在 setup_axes 之后,我尝试更改 graph_origin 以移动轴,也失败了。
在 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.py和FunctionGraph代码位于manimlib /mobject/functions.py以查看更多选项。