挑战用30个例子掌握Python数学可视化manim【例6】

例6 按要求写程序

  • 创建一个数值平面坐标系,x范围-6,6长度5;y范围-10,10长度5;该坐标系添加标注;位置在右侧三个单位
  • 在坐标系中画图fx=0.1*(x-5)x(x+5);图像显示-6,6范围,颜色绿色;
  • 将x范围中,图像与x轴围成的图像图上绿色黄色相间的颜色
  • 将公式标签显示在坐标系上方,缓冲0.2
  • 画直线(0,-2)到(-2,f(-2)),线黄色,10单位粗
    在这里插入图片描述
class Graphing(Scene):
  def construct(self):
    #创建数值平面
    my_plane = NumberPlane(x_range = [-6,6], x_length = 5, y_range = [-10,10], y_length = 5)
    #给数值平面坐标系添加标注
    my_plane.add_coordinates()
    #设置位置在右侧三个单位
    my_plane.shift(RIGHT*3)
    #在坐标系中画图
    my_function = my_plane.get_graph(lambda x :0.1*(x-5)*x*(x+5),x_range=[-6,6], color = GREEN_B)
    #图像与x轴围城的面积部分涂色
    area = my_plane.get_area(graph = my_function,
x_range = [-5,5], color = [BLUE,YELLOW])
    #将公式放在坐标系上方
    label = MathTex("f(x)=0.1x(x-5)(x+5)").next_to(
my_plane, UP, buff=0.2)
    #做垂线点(0,-2)到(-2,f(-2))
    #c2p将坐标转化为点
    #my_function.underlying_function能得到图像上的y坐标
    horiz_line =Line(
start = my_plane.c2p(0, my_function.underlying_function(-2)), end = my_plane.c2p(-2, my_function.underlying_function(-2)), stroke_color = YELLOW, stroke_width = 10)
    #画边然后填充的方式画坐标系
    self.play(DrawBorderThenFill(my_plane))
    #画出图像,和函数式
    self.play(Create(my_function),Write(label))
    #渐变显示面积部分
    self.play(FadeIn(area))
    #画出直线
    self.play(Create(horiz_line))
  • 15
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值