【发布时间】:2021-02-01 16:05:20
【问题描述】:
我正在尝试使用 matplotlibs 保存功能保存动画,但遇到了这样的错误并不断抛出 Numpy 错误。我去将 conda 和附加库更新到版本 4.9.2,所有附加库都是最新版本。之后动画不再运行,我不断收到以下错误消息:
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\cbook\__init__.py", line 224, in process
func(*args, **kwargs)
File "C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\animation.py", line 1259, in _on_resize
self._init_draw()
File "C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\animation.py", line 1706, in _init_draw
self._drawn_artists = self._init_func()
File "c:\Users\matth\Google Drive\University\Year 3\Individual Project\Source Code\path-planning\genetic_algorithm_3d\genetic_algorithm_3D.py", line 111, in init
line.set_3d_properties([])
File "C:\ProgramData\Anaconda3\lib\site-packages\mpl_toolkits\mplot3d\art3d.py", line 143, in set_3d_properties
zs = np.broadcast_to(zs, xs.shape)
AttributeError: 'list' object has no attribute 'shape'
导致上述错误的代码简化版如下:
import matplotlib.pyplot as plt
import matplotlib.animation as ani
import mpl_toolkits.mplot3d.axes3d as p3
def init():
line.set_data([], [])
line.set_3d_properties([])
return line,
def animate(i, line, points):
x = []
y = []
z = []
for point in points[i]:
x.append(point[0])
y.append(point[1])
z.append(point[2])
line.set_data(x, y)
line.set_3d_properties(z)
return line,
start = [0, 1, 2]
goal = [10, 9, 6]
points = [[1, 1, 1], [2, 2, 2], [3, 3, 3]]
fig = plt.figure()
ax = p3.Axes3D(fig)
ax.plot([start[0]], [start[1]], [start[2]], 'gs')
ax.plot([goal[0]], [goal[1]],[goal[2]], 'ms')
line, = ax.plot([], [], [], lw=2, color="red")
# PLEASE NOTE that I do not intend for this simplified version of code to run correctly, just for the error to no longer exist
# hopefully this will at least help with understanding the issue
animation = ani.FuncAnimation(fig, animate, 50, init_func=init, fargs=(line, points), interval=500, blit=True)
plt.show()
就像我提到的,这在我更新 conda 之前就可以工作,但我不愿意只是“回滚”版本而不了解它为什么首先被破坏。
对此的任何帮助将不胜感激!
【问题讨论】:
标签: python numpy matplotlib conda