2017-10-17 27 views
-1

私はこれが愚かな質問かもしれないことを理解しているので、私はpythonの初心者ですが、これにアニメーション化する問題があります。私はエラーが何かを見ることができません。私はこのエラーを受け取ります TypeError:f()missing 1必要な位置引数: 'Python、2つの引数を持つ関数をアニメ化する

私はscitoolsをダウンロードしていないので、アニメーション作成時にmatplotlibを使用します。

すべてのすべてのヘルプは非常に

import numpy as np 
import matplotlib.pyplot as plt 
import matplotlib.animation as animation 
from matplotlib import style 

x = np.linspace(-6, 6) 
tmax = 1 
tmin = -1 
t = np.linspace(-1, 1) 

def f(x, t): 
    term = (np.exp(-1*(x-3*t)**2))*np.sin(3*np.pi*(x-t)) 
    return term 
max_f = f(x[-1], t[-1]) 
plt.ion() 
y = f(x, tmax) 
lines = plt.plot(x, y) 
plt.axis([x[0], x[-1], -0.1, max_f]) 
plt.xlabel('x') 
plt.ylabel('f') 

counter = 0 
for ts in t: 
    y = f(x, t) 
    lines[0].set_ydata(y) 
    plt.legend(['ts=%4.2f' % ts]) 
    plt.draw() 
    plt.savefig('tmp_%04d.png' % counter) 
    counter += 1 


fig = plt.figure() 

anim = animation.FuncAnimation(fig, f, interval = 1000, blit=True) 
fig = plt.figure() 
plt.axis([x[0], x[-1], -0.1, max_f]) 
lines = plt.plot([], []) 
plt.xlabel('x') 
plt.ylabel('f') 

plt.show() 

EDIT、完全なトレースバックにappriciatedされます:Tkinterのコールバックで 例外 トレースバック(最新の呼び出しの最後): ファイル「C:\ユーザーは、私を\ \のAppDataを。\ローカル\プログラム\ Pythonの\ Python36-32 \ libに\ tkinter__init __ PY "コール リターンself.funcで、ライン1699、(*引数)

ファイルは、" C:\ユーザーはローカル\私\のAppDataを\します\ Program \ Python \ Python36-32 \ lib \ tkinter__init __。py "、行745、callit func(* args)

ファイル "C:¥Users¥me¥AppData¥Local¥Programs¥Python¥Python36-32¥lib¥site-packages¥matplotlib¥backends¥backend_tkagg.py"ファイル370、in idle_draw self.draw()

ファイル "C:¥Users¥me¥AppData¥Local¥Programs¥Python¥Python36-32¥lib¥site-packages¥matplotlib¥backends¥backend_tkagg.py" (self)

ファイルC:¥Users¥me¥AppData¥Local¥Programs¥Python¥Python36-32¥lib¥site-packages¥matplotlib¥backends¥backend_agg。 py "、線464、描画中 self.figure.draw(self.rende "ファイル:C:¥Users¥me¥AppData¥Local¥Programs¥Python¥Python36-32¥lib¥site-packages¥matplotlib¥artist.py"、63行目、draw_wrapper 描画(アーティスト、レンダラー、* args、** kwargs)

ファイル "C:¥Users¥me¥AppData¥Local¥Programs¥Python¥Python36-32¥lib¥site-packages¥matplotlib¥figure.py"描画の中で self.canvas.draw_event(レンダラ)

ファイル "C:¥Users¥me¥AppData¥Local¥Programs¥Python¥Python36-32¥lib¥site-packages¥matplotlib¥backend_bases.py"、行1823、in draw_event self.callbacks.process(s、event)

ファイル "C:¥Users¥me¥AppData¥Local¥Programs¥Python¥Python36-32¥lib¥site-packages¥matplotlib¥cbook.py"、行554、プロセス プロキシ(* args、** kwargsから)

ファイル "C:\ユーザーは、私に\のAppData \ローカル\プログラム\ Pythonの\ Python36-32 \ libには\サイト・パッケージを\ \ matplotlibのを\のcbook.py"、行416、コール リターンMTDで(* args、** kwargs)

ファイル "C:¥Users¥me¥AppData¥Local¥Programs¥Python¥Python36-32¥lib¥site-packages¥matplotlib¥animation.py" 881行目_start self._init_draw()

ファイル "C:¥Users¥me¥AppData¥Local¥Programs¥Python¥Python36-32¥lib¥site-packages¥matplotlib¥animation.py"、行1540、_init_draw self._draw_frame(next(self。

ファイル "C:¥Users¥me¥AppData¥Local¥Programs¥Python¥Python36-32¥lib¥site-packages¥matplotlib¥animation.py" 1562行目(_draw_frame内) self ._drawn_artists = self._func(framedata、* self._args)

はTypeError:F(1つの)必要な位置引数が不足して: 'T'

+0

あなたはあなたにエラーを与えている行を特定したい場合があります。 – pvg

+0

エラーだけでなく、完全なトレースバックを投稿してください。 – roganjosh

+0

また、質問を編集します。 –

答えて

0

としては、あなたが簡単にでき、これはエラーについて実際にはない、と述べましたFuncAnimationでtの値にfargsを指定してください。しかし、これはアニメーションを生成するコードにつながるわけではなく、したがって、exmapleで始まり、関数とコードを段階的に追加して何が起こるかを見てみましょう。

これは、最終的には次のようにつながる:

import numpy as np 
import matplotlib.pyplot as plt 
import matplotlib.animation as animation 

x = np.linspace(-6, 6) 
tmax = 1 
tmin = -1 
t = np.linspace(-1, 1) 

def f(x, t): 
    term = (np.exp(-1*(x-3*t)**2))*np.sin(3*np.pi*(x-t)) 
    return term 

y = f(x, tmax) 
lines = plt.plot(x, y) 
plt.axis([x[0], x[-1], -1, 1]) 
plt.xlabel('x') 
plt.ylabel('f') 

counter = [0] 
def animate(ts): 
    y = f(x, ts) 
    lines[0].set_ydata(y) 
    plt.legend(['ts=%4.2f' % ts]) 
    #plt.savefig('tmp_%04d.png' % counter) 
    counter[0] += 1 

anim = animation.FuncAnimation(plt.gcf(), animate, frames = t, interval = 1000) 
plt.show() 

enter image description here

関連する問題