FuncAnimation プロット (blit を使用) でアニメーション タイトルを動作させる方法がわかりません。http://jakevdp.github.io/blog/2012/08/18/matplotlib-animation-tutorial/およびPython/Matplotlib - Quickly Updating Text on Axesに基づいて、アニメーションを作成しましたが、テキスト部分が勝ちましたアニメ化しません。簡単な例:
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import numpy as np
vls = np.linspace(0,2*2*np.pi,100)
fig=plt.figure()
img, = plt.plot(np.sin(vls))
ax = plt.axes()
ax.set_xlim([0,2*2*np.pi])
#ttl = ax.set_title('',animated=True)
ttl = ax.text(.5, 1.005, '', transform = ax.transAxes)
def init():
ttl.set_text('')
img.set_data([0],[0])
return img, ttl
def func(n):
ttl.set_text(str(n))
img.set_data(vls,np.sin(vls+.02*n*2*np.pi))
return img, ttl
ani = animation.FuncAnimation(fig,func,init_func=init,frames=50,interval=30,blit=True)
plt.show()
を削除すると、テキストblit=True
は表示されますが、速度が遅くなります。plt.title
、ax.set_title
、および で失敗するようax.text
です。
編集:最初のリンクの 2 番目の例が機能する理由がわかりました。テキストはimg
パーツの中にありました。上記1.005
を a.99
にすると、私の言いたいことがわかるでしょう。おそらく、バウンディングボックスでこれを行う方法があるでしょう...