绘制函数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.wait(5)
self.stop_3dillusion_camera_rotation()
p=Draw()
p.render()
