アニメーションプロットを出力する関数を実装しようとしています。python matplotlib:関数内からFuncAnimationを呼び出すことができません
私はベースとして(matplotlibの例から)simple_anim.pyを取る場合:
"""
A simple example of an animated plot
"""
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
fig, ax = plt.subplots()
x = np.arange(0, 2*np.pi, 0.01) # x-array
line, = ax.plot(x, np.sin(x))
def animate(i):
line.set_ydata(np.sin(x+i/10.0)) # update the data
return line,
#Init only required for blitting to give a clean slate.
def init():
line.set_ydata(np.ma.array(x, mask=True))
return line,
ani = animation.FuncAnimation(fig, animate, np.arange(1, 200), init_func=init,
interval=25, blit=True)
plt.show()
効果的にそれが動作します。私は(変更パラメータを提供し、それぞれの可能なパラメータの値を明示的にファイルを行うことを避けるために)関数の中で、このコードを閉じた場合
しかし、:
"""
A simple example of an animated plot
"""
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
def a():
fig, ax = plt.subplots()
x = np.arange(0, 2*np.pi, 0.01) # x-array
line, = ax.plot(x, np.sin(x))
def animate(i):
line.set_ydata(np.sin(x+i/10.0)) # update the data
return line,
#Init only required for blitting to give a clean slate.
def init():
line.set_ydata(np.ma.array(x, mask=True))
return line,
ani = animation.FuncAnimation(fig, animate, np.arange(1, 200), init_func=init,
interval=25, blit=True)
plt.show()
して、関数を呼び出し、フィギュアプロットは白色のままです。実際、アニメート機能に入ることは決してありません。
私はいくつかの情報が不足していることを知っています。それがうまくいかない理由です。 誰かに私にいくつかのヒントを与えることができますか?
は、どうもありがとうございましたアンドレス
両方のコードは私のために正常に動作します。 'a'を呼び出すコードも投稿してください。 – Nabla