TypeError: Polygon.__init__() takes 2 positional arguments but 3 were given

《程序员数学:用Python学透线性代数和微积分》第3.5章,源码bug修正。

报错信息:

wang@wanggongdeMacBook-Air pythonTest % /usr/local/bin/python3 /Users/wang/Docum
ents/VSCode/pythonTest/chapter3/chapter3.py
Traceback (most recent call last):
File "/Users/wang/Documents/VSCode/pythonTest/chapter3/chapter3.py", line 196, in <module>
render(octahedron, color_map=matplotlib.colormaps.get_cmap('Blues'), lines=black)
File "/Users/wang/Documents/VSCode/pythonTest/chapter3/chapter3.py", line 194, in render
draw2d(*polygons, axes=False, origin=False, grid=None)
File "/Users/wang/Documents/VSCode/pythonTest/chapter3/draw2d.py", line 107, in draw2d
poly = Polygon(object.vertices, True)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: Polygon.__init__() takes 2 positional arguments but 3 were given

 

错误原因:

图书源码文件draw2d.py中107行的Polygon构建函数与新版本的matplotlib代码不兼容

 

修正方式:

打开draw2d.py

找到第107行

poly = Polygon(object.vertices, True)
修改为
poly = Polygon(object.vertices)

 

posted on 2023-10-17 11:36  王培  阅读(225)  评论(0编辑  收藏  举报

导航