Manimlib运行报错Axes无add_coordinates属性及Create未识别问题
报错原因与解决办法
这两个报错均由Manim版本不匹配导致:你参考的教程基于**社区维护版Manim(ManimCE)**编写,而你当前安装的是3Blue1Brown官方原版的manimlib(又称ManimGL),两个分支的API存在大量差异。
报错1:Create函数无法识别
- ManimCE中的
Create动画,在manimlib中对应名称为ShowCreation,直接替换函数名即可解决。
报错2:Axes object has no attribute 'add_coordinates'
add_coordinates是ManimCE独有的Axes方法,manimlib中没有这个API,你可以用add_numbers方法替代,功能完全一致。
适配manimlib的修改后完整代码
from manimlib import * import numpy as np class Anim4 (Scene): def construct(self): axes = Axes(x_range = [0, 5, 1], y_range= [0, 3, 1], x_length= 5, y_length=3, axis_config = {"include_tip": True, "numbers_to_exclude": [0]} ).add_numbers() axes.to_edge(UR) axis_labels = axes.get_axis_labels(x_label = "x", y_label = "f(x)") graph = axes.get_graph(lambda x : x**0.5, x_range = [0, 4], color = YELLOW) graphing_stuff = VGroup(axes, graph, axis_labels) self.play(DrawBorderThenFill(axes), Write(axis_labels)) self.play(ShowCreation(graph)) self.play(graphing_stuff.animate.shift(DOWN*4)) self.play(axes.animate.shift(LEFT*3), RUN_TIME = 3)
额外说明
如果你想完全匹配教程的API,可以卸载当前的manimlib,安装Manim社区版,安装后导入语句需要改为from manim import *,原代码不需要其他修改即可运行。
内容的提问来源于stack exchange,提问作者Opti_byte
相关产品推荐
相关产品推荐

