from manim import * import numpy as np class CartesianPlaneScene(Scene): def construct(self): # 一、创建坐标平面,先隐藏网格和数字 plane = NumberPlane( x_range=[-5, 5, 1], y_range=[-3, 3, 1], background_line_style={ "stroke_color": GREY, "stroke_width": 1, "stroke_opacity": 1, }, axis_config={ "include_tip": True, "tip_length": 0.15, } ) # 生成坐标数字,但先透明 plane.add_coordinates() plane.background_lines.set_opacity(0) plane.coordinate_labels.set_opacity(0) # 二、动画绘制 X 轴和 Y 轴 self.play( Create(plane.x_axis, run_time=2), Create(plane.y_axis, run_time=2), ) self.wait(1) # 三、写出刻度数字 self.play( FadeIn(plane.coordinate_labels, shift=DOWN*0.2), run_time=2 ) self.wait(1) # 四、绘制网格线 self.play( Create(plane.background_lines, run_time=3), ) self.wait(1) # 五、突出原点 origin_dot = Dot(plane.c2p(0, 0), color=RED) self.play(FadeIn(origin_dot), run_time=1) self.wait(2)