2017-11-12 10 views
-2

forループを使用して時間依存の方程式を解くコードを用意しています。各繰り返しの終わりに同じグラフを描画したいのですが、新しいグラフがあると古いグラフを保持したくないので、グラフがどのように変化するのかを見たいと思います。 。結果がどのように変化するかの映画のようなものでなければなりません。助けのためのPythonでforループをプロットする

for k in range (0,100,1): 

    #solve the equations 

    #plot graph (x,y) 

ありがとう:それはこのようなものです! matplotlib examplesから

+0

正しく表/コード/エラーをフォーマットするには、テーブルの各行に** 4 **有数のスペースを追加してください。ありがとう! – SteveFest

+2

Stackoverflowはプログラミングサービスではなく、解決のためにあなた自身の努力を示すべき具体的な単一の質問に答えることです。 –

答えて

0

""" 
========================= 
Simple animation examples 
========================= 

This example contains two animations. The first is a random walk plot. The 
second is an image animation. 
""" 

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


def update_line(num, data, line): 
    line.set_data(data[..., :num]) 
    return line, 

fig1 = plt.figure() 

data = np.random.rand(2, 25) 
l, = plt.plot([], [], 'r-') 
plt.xlim(0, 1) 
plt.ylim(0, 1) 
plt.xlabel('x') 
plt.title('test') 
line_ani = animation.FuncAnimation(fig1, update_line, 25, fargs=(data, l), 
            interval=50, blit=True) 

# To save the animation, use the command: line_ani.save('lines.mp4') 

fig2 = plt.figure() 

x = np.arange(-9, 10) 
y = np.arange(-9, 10).reshape(-1, 1) 
base = np.hypot(x, y) 
ims = [] 
for add in np.arange(15): 
    ims.append((plt.pcolor(x, y, base + add, norm=plt.Normalize(0, 30)),)) 

im_ani = animation.ArtistAnimation(fig2, ims, interval=50, repeat_delay=3000, 
            blit=True) 
# To save this second animation with some metadata, use the following command: 
# im_ani.save('im.mp4', metadata={'artist':'Guido'}) 

plt.show() 
関連する問題