2016-08-14 17 views
0

matplolibs FuncAnimationを使用してアニメーションをコーディングして、下の図のようなモデルを作成しました。 。画像:以下TypeError:matoplotlibアニメーションの 'NoneType'オブジェクトが反復可能なエラーではありません

The model

はコードです。 hをリストを分離するリストとして考えてみましょう。最初のものは各フレームで変更する円を含み、2番目はサークルの開始色を別々の 'k'と 'w'文字列の形で含みます。時間の例:

[[1,3,4,1.....]['k','w','k','w','w'....]] 

コード:輸入、使用している

n=5 
fig = plt.figure(figsize=(n,n)) 
x =[i%n+1 for i in range(0,n**2)] 
y =[i/n+1 for i in range(n**2)] 
h=giving_data_for_visual(2,n,3,1,2) 
cl=h[1] 
colors='' 
for i in cl: 
    colors+=i 
changes_list=h[0] 
scat=plt.scatter(x, y,s=50,facecolors=colors, alpha=0.5) 

def update(frame): 
    global colors,change_list 
    t=(cl[changes_list[frame]]=='k') 
    cl[changes_list[frame]]='k' if t else 'w' 
    colors=cl 
    scat.set_facecolors(colors) 

ani=animation.FuncAnimation(fig, update, interval=10, blit=True,frames=len(changes_list)) 
plt.show() 

は以下の通りである(一部は、プログラムのこの部分のために意図されていない):

from random import randint 
from random import uniform 
from math import exp 
from math import log 
import matplotlib.pyplot as plt 
import numpy as np 
from numpy import std 
from matplotlib import animation 

しかし、コードを実行すると最初のフレームだけが表示されます(上記のモデルiに類似しています)。ウィンドウを閉じると、このエラーが表示されます。

Exception in Tkinter callback 
Traceback (most recent call last): 
    File "C:\Users\Yael\Desktop\WinPython-64bit-2.7.10.2\python-2.7.10.amd64\lib\lib-tk\Tkinter.py", line 1536, in __call__ 
    return self.func(*args) 
    File "C:\Users\Yael\Desktop\WinPython-64bit-2.7.10.2\python-2.7.10.amd64\lib\lib-tk\Tkinter.py", line 587, in callit 
func(*args) 
    File "C:\Users\Yael\Desktop\WinPython-64bit-2.7.10.2\python-2.7.10.amd64\lib\site-packages\matplotlib\backends\backend_tkagg.py", line 143, in _on_timer 
TimerBase._on_timer(self) 
    File "C:\Users\Yael\Desktop\WinPython-64bit-2.7.10.2\python-2.7.10.amd64\lib\site-packages\matplotlib\backend_bases.py", line 1290, in _on_timer 
ret = func(*args, **kwargs) 
    File "C:\Users\Yael\Desktop\WinPython-64bit-2.7.10.2\python-2.7.10.amd64\lib\site-packages\matplotlib\animation.py", line 925, in _step 
still_going = Animation._step(self, *args) 
    File "C:\Users\Yael\Desktop\WinPython-64bit-2.7.10.2\python-2.7.10.amd64\lib\site-packages\matplotlib\animation.py", line 784, in _step 
self._draw_next_frame(framedata, self._blit) 
    File "C:\Users\Yael\Desktop\WinPython-64bit-2.7.10.2\python-2.7.10.amd64\lib\site-packages\matplotlib\animation.py", line 802, in _draw_next_frame 
self._pre_draw(framedata, blit) 
    File "C:\Users\Yael\Desktop\WinPython-64bit-2.7.10.2\python-2.7.10.amd64\lib\site-packages\matplotlib\animation.py", line 815, in _pre_draw 
self._blit_clear(self._drawn_artists, self._blit_cache) 
    File "C:\Users\Yael\Desktop\WinPython-64bit-2.7.10.2\python-2.7.10.amd64\lib\site-packages\matplotlib\animation.py", line 853, in _blit_clear 
    axes = set(a.axes for a in artists) 
TypeError: 'NoneType' object is not iterable 

私はこのバグを解決できません。助けを前にありがとう:)。

答えて

0

documentation of FuncAnimationupdate機能が変更されたアーティスト返すべきであると述べている:

If blit=True, func and init_func should return an iterable of drawables to clear. 

あなたは

def update(frame): 
    global colors,change_list 
    t=(cl[changes_list[frame]]=='k') 
    cl[changes_list[frame]]='k' if t else 'w' 
    colors=cl 
    scat.set_facecolors(colors) 
    return scat 

にあなたの機能を変更することがありますが、私はあなたのコードに追加され、最後の行に注意してください。

+0

ありがとうございます。今私はリターンを逃したためにひどく愚かだと感じる。 – nyenyu

+0

さて、関数が何かを返す必要があることは明らかではありません。 –

関連する問題