Python 使用matplotlib动画时发生TypeError

Python 使用matplotlib动画时发生TypeError,python,matplotlib,animation,Python,Matplotlib,Animation,我无法创建粒子运动的动画。粒子位置数据(以及其他属性)存储在标题为“历史”的词典中。通常,此animationstation.py文件从MAIN.py文件导入“历史”。然而,为了便于参考,我在history.txt文件中包含了一个简短的示例,该动画文件从中读取“history”字典。.txt文件的内容是: [{'m': [6.28e-16, 6.28e-16, 6.28e-16, 6.28e-16], 'q': [3.14e-15, 3.14e-15, 3.14e-15, 3.14e-15],

我无法创建粒子运动的动画。粒子位置数据(以及其他属性)存储在标题为“历史”的词典中。通常,此animationstation.py文件从MAIN.py文件导入“历史”。然而,为了便于参考,我在history.txt文件中包含了一个简短的示例,该动画文件从中读取“history”字典。.txt文件的内容是:

[{'m': [6.28e-16, 6.28e-16, 6.28e-16, 6.28e-16], 'q': [3.14e-15, 3.14e-15, 3.14e-15, 3.14e-15], 'rad': [5e-07, 5e-07, 5e-07, 5e-07], 'x': [0, 0.0, 0.0, 0.0], 'y': [0, 9.600000000000001e-08, 1.9200000000000003e-07, 2.8800000000000004e-07], 'z': [0.020094615, 0.020094615002866825, 0.020094615011467296, 0.020094615025801416], 'vx': [0, 0.0, 0.0, 0.0], 'vy': [96, 96.0, 96.0, 96.0], 'vz': [0, 0.00573364787230897, 0.01146729574461794, 0.017200943616926912], 'ax': [0, 0.0, 0.0, 0.0], 'ay': [0, 0, 0, 0], 'az': [0, 5733647.87230897, 5733647.87230897, 5733647.87230897], 'F_Ex': [0, 0.0, 0.0, 0.0], 'F_Ey': [0, 0.0, 0.0, 0.0], 'F_Ez': [0, 3.6007370244900336e-09, 3.6007370244900336e-09, 3.6007370244900336e-09], 'F_Cx': [0, 0.0, 0.0, 0.0], 'F_Cy': [0, 0.0, 0.0, 0.0], 'F_Cz': [0, 0.0, 0.0, 0.0], 'F_Gx': [0, 0, 0, 0], 'F_Gy': [0, 0, 0, 0], 'F_Gz': [0, 0, 0, 0], 'F_Dx': [0, 0, 0, 0], 'F_Dy': [0, 0, 0, 0], 'F_Dz': [0, 0, 0, 0], 'parent_index': 0, 'number': 0}]
代码似乎在makeFigure()和init()fn.s中顺利运行,但从未进入animate()fn

以下是我运行时收到的错误消息:

/Users/mckennadavis/.virtualenvs/gitdeli/bin/python/Users/mckennadavis/PycharmProjects/gitdeli/SimpleAnim.py
Traceback (most recent call last):
  File "/Users/mckennadavis/PycharmProjects/gitdeli/SimpleAnim.py", line 56, in <module>
    anim.save('basic_animation.mp4', writer=writer)
  File "/Users/mckennadavis/.virtualenvs/gitdeli/lib/python3.7/site-packages/matplotlib/animation.py", line 1128, in save
    anim._init_draw()  # Clear the initial frame
  File "/Users/mckennadavis/.virtualenvs/gitdeli/lib/python3.7/site-packages/matplotlib/animation.py", line 1706, in _init_draw
    self._drawn_artists = self._init_func()
TypeError: 'list' object is not callable

Process finished with exit code 1
/Users/mckennadavis/.virtualenvs/gitdeli/bin/python/Users/mckennadavis/PycharmProjects/gitdeli/SimpleAnim.py
回溯(最近一次呼叫最后一次):
文件“/Users/mckennadavis/PycharmProjects/gitdeli/SimpleAnim.py”,第56行,在
anim.save('basic_animation.mp4',writer=writer)
文件“/Users/mckennadavis/.virtualenvs/gitdeli/lib/python3.7/site packages/matplotlib/animation.py”,第1128行,保存
动画。_init_draw()#清除初始帧
文件“/Users/mckennadavis/.virtualenvs/gitdeli/lib/python3.7/site packages/matplotlib/animation.py”,第1706行,在初始绘图中
self.\u draw\u artists=self.\u init\u func()
TypeError:“列表”对象不可调用
进程已完成,退出代码为1
您需要将函数
init
传递给
init\u func=
而不是函数
init()的返回值

注意
init

animation.FuncAnimation(fig, animate, init_func=init, ...)
animation.FuncAnimation(fig, animate, init_func=init, ...)