我正在开发一个程序,以使电场可视化,并且我希望基于电荷列表(位置,电荷等)来更新图形。完整代码可以在here中找到,但是由于它接近300行(主要是物理和数学),因此我决定省略大部分代码,以使问题更加清楚。
我已经定义了下面的动画来对预期的图形进行动画处理(同样,animate()内部函数的来龙去脉非常复杂,但是可以在链接中找到)。
def animate():
"""
This function animates the graph
:param i:
:return:
"""
inputs = get_inputs(charges,resolution)
create_graph(inputs[0],inputs[1])
charges = []
resolution = 50
ani = animation.FuncAnimation(fig1, animate(), interval=1000)
plt.show()
不幸的是,运行该程序后,我收到以下错误:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python27\lib\lib-tk\Tkinter.py", line 1542, in __call__
return self.func(*args)
File "C:\Python27\lib\site-packages\matplotlib\backends\backend_tkagg.py", line 283, in resize
self.show()
File "C:\Python27\lib\site-packages\matplotlib\backends\backend_tkagg.py", line 354, in draw
FigureCanvasAgg.draw(self)
File "C:\Python27\lib\site-packages\matplotlib\backends\backend_agg.py", line 474, in draw
self.figure.draw(self.renderer)
File "C:\Python27\lib\site-packages\matplotlib\artist.py", line 62, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "C:\Python27\lib\site-packages\matplotlib\figure.py", line 1165, in draw
self.canvas.draw_event(renderer)
File "C:\Python27\lib\site-packages\matplotlib\backend_bases.py", line 1809, in draw_event
self.callbacks.process(s, event)
File "C:\Python27\lib\site-packages\matplotlib\cbook.py", line 563, in process
proxy(*args, **kwargs)
File "C:\Python27\lib\site-packages\matplotlib\cbook.py", line 430, in __call__
return mtd(*args, **kwargs)
File "C:\Python27\lib\site-packages\matplotlib\animation.py", line 661, in _start
self._init_draw()
File "C:\Python27\lib\site-packages\matplotlib\animation.py", line 1221, in _init_draw
self._draw_frame(next(self.new_frame_seq()))
File "C:\Python27\lib\site-packages\matplotlib\animation.py", line 1243, in _draw_frame
self._drawn_artists = self._func(framedata, *self._args)
TypeError: 'NoneType' object is not callable
但是,这些错误实际上都不与程序中的一行直接相关,因此我对任何解决方案都一无所知。任何帮助都将不胜感激。