-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
54 lines (51 loc) · 1.41 KB
/
test.py
File metadata and controls
54 lines (51 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from function.tangent import AdvancedFunction
from machinelearning.LinearModel.LinearRegression import LinearRegression
import pandas as pd
from manim import *
def tan():
# 创建并渲染第一个函数
viz1 = AdvancedFunction(
func=lambda x: (x + 3) * (x - 2) * (x + 1),
tangent_at=1,
show_limit_animation=False,
x_range=[-14, 14, 1],
y_range=[-10, 10, 1],
x_length=14,
y_length=8,
output_file="polynomial.mp4",
quality="high"
)
viz1.render()
# 创建并渲染第二个函数
viz2 = AdvancedFunction(
func=lambda x: np.sin(x),
tangent_at=np.pi / 4,
show_limit_animation=True,
x_range=[-np.pi, np.pi, np.pi / 2],
y_range=[-1.5, 1.5, 0.5],
output_file="sine.mp4",
quality="high"
)
viz2.render()
def linear():
# 创建示例数据
np.random.seed(42)
x = np.linspace(-4, 4, 20)
y = -1.3 * x + 0.5 + np.random.randn(20) * 2.0
example_data = pd.DataFrame({'x': x, 'y': y})
# 创建并渲染动画
scene = LinearRegression(
x_range=[-5, 5],
y_range=[-8, 8],
x_length=10,
y_length=8,
axis_config={"color": WHITE},
target_color=BLUE,
fitting_color=RED,
example_point=example_data
)
scene.UnivariateLinearRegression()
scene.render()
if __name__ == "__main__":
tan()
linear()