例5 按要求实现代码
- 创建一个坐标系x轴范围0-5间隔1显示,不显示0点,y轴范围0-3间隔1显示,不显示0点,坐标系位置在右上方,x轴显示x,y轴显示f(x)。
- 在坐标系画f(x)=(x^2)/2图像x[0,4]。
- 以group方式将坐标系,各轴标识,图像,整体向下移动4个单位。
- 单独将坐标系向左移动3个单位。
![在这里插入图片描述](https://img-blog.csdnimg.cn/551287bc9ca94fe7a6741b16f8e2a73c.jpg)
![在这里插入图片描述](https://img-blog.csdnimg.cn/b9685c1a4d5143b184e1920241fb07ad.jpg)
class GraphingMovement(Scene):
def construct(self):
#创建坐标系
axes = Axes(x_range = [0,5,1], y_range = [0,3,1],
axis_config={"include_tips":true,"numbers_to_exclude":[0]}).add_coordinates()
#位置在右上角
axes.to_edge (UR)
#设置xy轴的显示tips,并拿到该对象
axis _labels = axes.get_axis_labels(x_label = "x", y _label = "f(x)")
#在坐标系画图,并得到图像对象
graph = axes.get_graph(lambda x : x**0.5, x _range = [0,4], color = YELLOW)
#将坐标系,坐标tips,图像组队
graphing_stuff = VGroup(axes, graph, axis _labels)
#动画画出坐标系和labels
self.play(DrawBorderThenFill(axes), Write(axis _labels))
#动画创建图像
self.play(Create(graph))
#将组整体移动四个单位
self.play(graphing_stuff.animate.shift(DOWN*4), run_time=3)
#将坐标系单独向左移动
self.play(axes.animate.shift(LEFT*3), run_time = 3)