Manim-基础入门图形,坐标轴

文章介绍了如何在Python中使用`NumberPlane`、`Axes`和`NumberLine`创建坐标轴,包括实线、虚线和非线性变换的应用。通过`create`和`animate`方法展示了线性映射和非线性变换在图形构造中的应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.坐标轴展示

  (1)
def construct(self):
    grid=NumberPlane(
         axis_config={"stroke_color":RED}#这个是设置xy轴颜色用的
    )
    self.play(Create(grid))
    self.wait(2)

这个是我最喜欢的坐标轴

     (2)  

def construct(self):
    axes=Axes(x_range=[-2,2],y_range=[-2,2])
    line1=Line()
    line2=DashedLine(np.array([-2,-2,0]),np.array([0,2,0])
        )#虚线
    line1.put_start_and_end_on(
        np.array([-2, 2, 0]), np.array([0, -2, 0])
    )#实线
    line3=Line(
        np.array([-2,-2,0]),
        np.array([-2,2,0]),
        color=RED,
        path_arc=-4.39#拉直线为弧线
    )
    self.play(Create(axes))
    self.play(Create(line1))
    self.play(Create(line2))
    self.play(Create(line3))
    self.wait(2)

# self.add(axes.get_axis_labels())#获取x,y
# axes.add_coordinates()#可以显示全部的数轴值
# axes.add_coordinates(
#     [-1,2],[-2,1]
# )#还是都是点

上述为补充的几种应用

(第二种轴及加上直线的运用)

   (3)

def construct(self):

axis=NumberLine(
    x_range=[-2,2,0.5],#第三个为间隔
    include_ticks=True,#包含刻度线
    include_tip=True,#在末端添加箭头
    include_numbers=False,#标上值
    unit_size=1.5,#视频上的效果:单位长度为1.5
    #label_direction=UP可以设置数标在上面


).shift(LEFT*3)
axis.add_numbers([-1,2])#这个不是一个区间,是两个点,表示展示两个点的刻度值
self.add(axis)

(4)进行线性变换

def construct(self):
    grid=NumberPlane(
         axis_config={"stroke_color":RED}#这个是设置xy轴颜色用的
    )
    self.play(Create(grid))
    self.wait(2)

    self.play(grid.animate.apply_function(lambda p:p+RIGHT*p[1]))
    self.wait(2)#这是基于线性映射,不线性的映射在下面

 (5)

非线性变换

def construct(self):
    grid=NumberPlane(
         axis_config={"stroke_color":RED}#这个是设置xy轴颜色用的
    )
    self.play(Create(grid))
    self.wait(2)

    # self.play(grid.animate.apply_function(lambda p:p+RIGHT*p[1]))
    # self.wait(2)#这是基于线性映射,不线性的映射在下面
    grid.prepare_for_nonlinear_transform()
    self.play(
        grid.animate.apply_function(
            lambda p: p
                      + np.array(
                [
                    np.sin(p[1]),
                    np.sin(p[0]),
                    0,
                ],
            ),
        ),
        run_time=3,
    )

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值