赞
踩
相信很多同学就算没听过3Blue1Brown,也一定曾看过他们出品的视频,其从独特的视觉角度解说各种数学概念,内容包括线性代数、微积分、神经网络、傅里叶变换以及四元数等晦涩难懂的知识点。例如最火的《线性代数本质》系列视频。
那么这些视频是如何制作的呢?
这里需要引入的是Python的Manim视频支持引擎——专门用于支持数学可视化的媒体引擎,通过Manim并结合Python编程就可以实现3Blue1Brown的视频效果。本文给出Manim最新发行版的安装教程,因为网上的教程基本都过时了,容易踩坑。
动画1:
动画2:(动图始终超过大小,放不上来)
进入ffmpeg官网,点击如图所示的按钮
接着下载安装包
下载完后直接解压,并设置环境变量
进入官网MikTex官网,下载对应操作系统的安装包。
解压后运行安装程序.exe即可(环境变量会自动配置)
进入官网dvisvgm下载相应操作系统的安装包,解压后运行安装程序即可。
通过git bash运行下面命令
git clone https://github.com/3b1b/manim.git
cd manim
# 安装python依赖
pip install -e .
python -m pip install -r requirements.txt
2021版重点:错误复现如下
LaTeX Error! Not a worry, it happens to the best of us. Traceback (most recent call last): File "D:\Program Files\Python3\Scripts\manimgl-script.py", line 33, in <module> sys.exit(load_entry_point('manimgl', 'console\_scripts', 'manimgl')()) File "d:\public\manim\manimlib\\_\_main\_\_.py", line 17, in main scene.run() File "d:\public\manim\manimlib\scene\scene.py", line 75, in run self.construct() File "example\_scenes.py", line 29, in construct IntegerMatrix(matrix, include\_background\_rectangle=True), File "d:\public\manim\manimlib\mobject\matrix.py", line 81, in __init__ self.add_brackets() File "d:\public\manim\manimlib\mobject\matrix.py", line 111, in add_brackets bracket_pair = Tex("".join([ File "d:\public\manim\manimlib\mobject\svg\tex\_mobject.py", line 167, in __init__ super().__init__(full_string, **kwargs) File "d:\public\manim\manimlib\mobject\svg\tex\_mobject.py", line 42, in __init__ filename = tex_to_svg_file(full_tex) File "d:\public\manim\manimlib\utils\tex\_file\_writing.py", line 54, in tex_to_svg_file tex_to_svg(tex_file_content, svg_file) File "d:\public\manim\manimlib\utils\tex\_file\_writing.py", line 62, in tex_to_svg svg_file = dvi_to_svg(tex_to_dvi(tex_file)) File "d:\public\manim\manimlib\utils\tex\_file\_writing.py", line 97, in tex_to_dvi with open(log_file, "r") as file: FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\Tex\\cf5d7f9f2e57398a.log'
该问题的最终解决方案是配置manim/manimlib/default_config.yml
的缓存路径,其中"D:\\AIProject\\test\\manim\\tex"
是manim
目录下新建的一个空文件夹,用来存放tex输出文件。
进入manim
目录下运行:
manimgl example_scenes.py OpeningManimExample
即可得到动画2的效果。
新建main.py
文件,运行下面代码
from manimlib import \*
class GraphExample(Scene):
def construct(self):
axes = Axes((-3, 10), (-1, 8))
axes.add_coordinate_labels()
self.play(Write(axes, lag_ratio=0.01, run_time=1))
# Axes.get\_graph will return the graph of a function
sin_graph = axes.get_graph(
lambda x: 2 \* math.sin(x),
color=BLUE,
)
# By default, it draws it so as to somewhat smoothly interpolate
# between sampled points (x, f(x)). If the graph is meant to have
# a corner, though, you can set use\_smoothing to False
relu_graph = axes.get_graph(
lambda x: max(x, 0),
use_smoothing=False,
color=YELLOW,
)
# For discontinuous functions, you can specify the point of
### 最后
Python崛起并且风靡,因为优点多、应用领域广、被大牛们认可。学习 Python 门槛很低,但它的晋级路线很多,通过它你能进入机器学习、数据挖掘、大数据,CS等更加高级的领域。Python可以做网络应用,可以做科学计算,数据分析,可以做网络爬虫,可以做机器学习、自然语言处理、可以写游戏、可以做桌面应用…Python可以做的很多,你需要学好基础,再选择明确的方向。这里给大家分享一份全套的 Python 学习资料,给那些想学习 Python 的小伙伴们一点帮助!
#### 声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/956907
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。