manim 绘制数学图像

绘制函数y=x^2的图像.

from manim import *  
 
class DrawFunctionGraph(Scene):  
    def construct(self): 
        ax=Axes(
            x_axis_config={
                "color": RED,
                "stroke_width": 1,
            },
            y_axis_config={
                "color": GREEN,
                "stroke_width": 3,
            })
        # 定义函数  
        function = lambda x: x ** 2  
 
        # 创建 FunctionGraph 对象  
        graph = FunctionGraph(function, x_range=(-3, 3), color=YELLOW)  
 
        # 绘制图形  
        self.add(ax)  
        self.play(Write(graph))

p=DrawFunctionGraph()
p.render()
       

在这里插入图片描述

空间曲线图像

from manim import *
import numpy as np
class Draw(ThreeDScene):
    
    
    def construct(self):
        curve1 = ParametricFunction(
            lambda x: np.array([
                np.cos(x),
                np.sin(x),
                x * 0.1
            ]), color=RED, t_range = np.array([-5*TAU, 5*TAU, 0.01])
        ).set_shade_in_3d(True)

        axes = ThreeDAxes(
            x_axis_config={
                "color": RED,
                "stroke_width": 1,
            },
            y_axis_config={
                "color": GREEN,
                "stroke_width": 3,
            },
            z_axis_config={
                "color": BLUE,
                "stroke_width": 5,
            },
        ).scale(0.6)
        labels = axes.get_axis_labels(
            Text("人口", font_size=20, color=RED),
            Text("年龄", font_size=20, color=GREEN),
            Text("收入", font_size=20, color=BLUE),
        )

        
        self.add(axes,curve1)
        self.set_camera_orientation(phi=80 * DEGREES, theta=60 * DEGREES)
        self.begin_3dillusion_camera_rotation(rate=2)
        #设置背景色
        #self.camera.background_color = WHITE 

        #是否生成为视频,不过不等待就是一张图片
        self.wait(5)
        
        #是否生成视觉在左右晃荡视频
        self.stop_3dillusion_camera_rotation()
p=Draw()
p.render()

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值