私は、いくつかのグラフを生成した後、フォートランでいくつかのシミュレーションから出力データを読み、軌道の動画を作ります。最初は、アニメーションにblittingを使用しなかったので、動作していた間は非常に遅かったです。Matplotlibのアニメーション更新機能がデータを設定していません
元々私が欲しがっていたアニメーションは、後に続くエフェクトを作成するために、アルファが減少する5つの一連のデータがあるため、自分自身に分散させたいと思っていました。私は、スクリプトを実行すると、ウィンドウが一瞬のために表示され、画面上の黄色の円が示す、非常に明確にあり、今
def animate(frame):
jptx, jpty = jx[frame-3:frame], jy[frame-3:frame]
cptx, cpty = cx[frame-3:frame], cy[frame-3:frame]
eptx, epty = ex[frame-3:frame], ey[frame-3:frame]
gptx, gpty = gx[frame-3:frame], gy[frame-3:frame]
iptx, ipty = ix[frame-3:frame], iy[frame-3:frame]
ax2.clear()
ax2.scatter(jptx, jpty, s=32, c=ablue, marker="s", label='Jupiter')
ax2.scatter(cptx, cpty, s=8, c=ared, marker="o", label='Callisto')
ax2.scatter(eptx, epty, s=8, c=agreen, marker="o", label='Europa')
ax2.scatter(gptx, gpty, s=8, c=ablack, marker="o", label='Ganymede')
ax2.scatter(iptx, ipty, s=8, c=ayellow, marker="o", label='Io')
ax2.set_xlim(-3, 7)
ax2.set_ylim(-3, 4)
animation = animation.FuncAnimation(fig2, animate, interval=0.5, frames=jt.size)
print('Begin saving animation')
animation.save('Tabbys Star.mp4', writer='ffmpeg', fps=60)
print('Animation saved')
plt.show()
:ここに私の元の(非ブリット)更新機能です背景が描画されています。ただし、ウィンドウはすぐに終了します。これは、2回目の試みに関連するコードです。この試行で黄色の円が追加されました。
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import numpy as np
# j_file = location + 'JUPITER.aei'
# jt, jx, jy, jz = read_data(j_file)
jt, jx, jy, jz = np.random.random([100,4]), np.random.random([100,4]), np.random.random([100,4]), np.random.random([100,4])
# c_file = location + 'CALLISTO.aei'
# ct, cx, cy, cz = read_data(c_file)
ct, cx, cy, cz = np.random.random([100,4]), np.random.random([100,4]), np.random.random([100,4]), np.random.random([100,4])
alphas = [0.25, 0.5, 0.75, 1]
ablue = np.zeros((4, 4))
ablue[:, 2] = 1.0
ablue[:, 3] = alphas
ared = np.zeros((4, 4))
ared[:, 0] = 1.0
ared[:, 3] = alphas
fig2 = plt.figure()
ax2 = fig2.add_subplot(111, aspect='equal')
xdata, ydata = np.zeros((4,)), np.zeros((4,))
jpt, = plt.plot(xdata, ydata, marker='.', ms=32, c=ablue, label='Jupiter')
cpt, = plt.plot(xdata, ydata, marker='.', ms=8, c=ared, label='Callisto')
def init():
ax2.set_xlim(-3, 7)
ax2.set_ylim(-3, 4)
circle = plt.Circle((0, 0), 0.1, color='y')
ax2.add_patch(circle)
for pt in [jpt, cpt]:
pt.set_data(np.zeros((4,)), np.zeros((4,)))
return jpt, cpt
def animate(frame, j, c):
jptx, jpty = jx[frame-3:frame], jy[frame-3:frame]
cptx, cpty = cx[frame-3:frame], cy[frame-3:frame]
j.set_data(jptx, jpty)
c.set_data(cptx, cpty)
return j, c
animation = animation.FuncAnimation(fig2, animate, fargs=(jpt, cpt), interval=0.5, frames=jt.size, init_func=init, blit=True)
print('Begin saving animation')
# animation.save('Tabbys Star.mp4', writer='ffmpeg', fps=60)
print('Animation saved')
plt.show()
私はまた、最終的に伝説といくつかの軸ラベルを追加したいが、私はそれが正常に行うことができると信じています。
2番目のコードスニペットでアニメーションの問題は何ですか? (再び)わかりやすくするために編集された
おかげ
ようになり、コードが実行可能であるように。そのような[mcve]を含めるように質問を編集したら、人々が手助けすることができます。必要な情報には、スクリプトの実行方法(環境、バージョンなど)も含まれます。 – ImportanceOfBeingErnest
明瞭にするために編集されました。天文学データの代わりに、データ(例えば、上記のjt、jx、jy、jz)は、同じ長さのnp 1次元配列(すなわち、jt.size = ix.sizeなど)としてシミュレートすることができます –
[mcve]誰かが質問からコードをコピーしてコピーして実行し、問題の問題を観察できるということです。代わりに、質問からの例から20分の例を一緒に微調整する必要がある場合、私はすぐに手を差し伸べることなくあきらめるだろう。 – ImportanceOfBeingErnest