2017-03-22 13 views
0

以下のコードは、私が書いたコードのスニペットです。基本的にはtkinterウィンドウにグラフが表示されますが、アニメーションの追加には苦労します。グラフを更新(更新)します。以下は、私が得ているエラーです、どんな助けも大いに感謝されるでしょう。matplotlib.animation - AttributeError: 'NoneType'オブジェクトに 'new_timer'属性がありません

Traceback (most recent call last): 
    File "C:\Users\nasto\Documents\Company\CMSFRAME.py", line 163, in <module> 
    ani = animation.FuncAnimation (f, animate, interval=1000) 
    File "C:\Users\nasto\AppData\Local\Programs\Python\Python36-32\lib\site-packages\matplotlib\animation.py", line 1462, in __init__ 
    TimedAnimation.__init__(self, fig, **kwargs) 
    File "C:\Users\nasto\AppData\Local\Programs\Python\Python36-32\lib\site-packages\matplotlib\animation.py", line 1225, in __init__ 
    event_source = fig.canvas.new_timer() 
AttributeError: 'NoneType' object has no attribute 'new_timer' 

私のコードの抜粋:

 canvas = FigureCanvasTkAgg(f, self) 
     canvas.show() 
     canvas.get_tk_widget().pack(side=tk.LEFT, fill=tk.BOTH, expand = True) 
     toolbar = NavigationToolbar2TkAgg(canvas, self) 
     toolbar.update() 
     canvas._tkcanvas.pack(side=tk.LEFT, fill=tk.BOTH, expand = True) 

f = Figure(figsize = (5,5), dpi=100) 
a = f.add_subplot(111) 

def animate(interval): 
    pullData = open('financeData.txt','r').read() 
    dataList = pullData.split('\n') 
    xList = [] 
    yList=[] 
    for eachLine in dataList: 
     if len(eachline) >1: 
      x, y = eachLine.split(',') 
      xList.append(int(x)) 
      yList.append(int(x)) 
    a.clear() 
    a.plot(xList, yList) 

app = start() 
ani = animation.FuncAnimation (f, animate, interval=1000) 
+0

animate関数は何も返しません。例を確認してくださいhttp://matplotlib.org/2.0.0/examples/animation/animate_decay.html – maz

+0

まだエラーが表示されます –

+0

何を変更しましたか?あなたのアニメーション関数は、 ''行、= ax.plot([]、[]、lw = 2) ''のような行オブジェクトを返さなければなりません。あなたは何も返しません。 – maz

答えて

1

エラーは、基本的に図がキャンバスを持っていないことを示しています。

数字がFigureCanvasTkAggに追加された後でアニメーションを開始することを確実にする必要がないようにするには、我々は問題の完全なコードが不足しているので、私は仕事に報告されている他のいくつかの完全な例にあなたをのみリンクすることができます。

第2のケースで
  1. Embedding matplotlib canvas into tkinter GUI - plot is not showing up, but no error is thrown
  2. Python. Error using animation.FuncAnimation

からコード問題はまったく同じエラーを生成し、可能な解決策はtkクラスにアニメーションを組み込むことです。