Takuya Miyashita
This site
Web
Start:
*matplotlib 動画・アニメーション作成 [#ue24135e]
主な手法は2つらしい.~
加えて,imagemagick の convert を Python から使う方法もあ...
[[Matplotlib の pause を使ったアニメーションを簡単に動画...
個人的には画像で掃き出して動画は[[ ffmpeg >Linux/ffmpeg]]...
インポートは下記の通り.
#codeprettify(lang-python){{
import matplotlib.pyplot as plt
import matplotlib.animation as animation
}}
**animation.FuncAnimation [#z900e0e1]
ArtistAnimationは タイトルを動的に設定できない?ため,Fun...
このコマンドでは,各ステップに対応する描画 function を作...
また,その function の第一入力引数は,時間ステップを示す...
下記は pcolor で書いて,gif で保存するときのサンプル.
#codeprettify(lang-python){{
def update_pcolor(istep, ax, X, Y, pcdata, time_in_dateti...
PC = ax.pcolor(X, Y, pcdata[istep,:,:])
PC.set_clim([0.,1.])
ax.set_title(time_in_datetime[istep].strftime('%Y/%m/...
}}
#codeprettify(lang-python){{
def main():
fig = plt.figure()
ax = fig.add_subplot(111)
# とりあえず1回書いとく
PC = ax.pcolor(lon, lat, pcdata[0,:,:])
ax.axis('scaled')
ax.set_xlim(xmin, xmax)
ax.set_ylim(ymin, ymax)
cbar = fig.colorbar(PC)
cbar.ax.set_ylabel('colorbar label [unit]')
ax.set_yticks(yticks)
ax.set_xlabel('X-axis')
ax.set_ylabel('Y-axis')
ani = animation.FuncAnimation(fig, update_pcolor, far...
ani.save('filename.gif',writer='XXX')
}}
update_pcolor に xlabel 等を入れると毎回描くことになり時...
animation.FuncAnimation の2番目の入力引数には,function ...
その function(update_pcolor) の引数は,第二引数以降から f...
update_pcolor の第一引数は,frames の数にしたがって順番に...
frames=10 とすると,istep=0〜9 までのものを書く.~
interval で1フレーム当たりの表示時間(ms)を指定できる.
**animation.ArtistAnimation [#e81b2910]
plot や pcolor などの描画コマンドが返すものをステップごと...
#codeprettify(lang-python){{
fig = plt.figure()
ax = fig.add_subplot(111)
snap = []
for istep in np.arange(Nstart, Nend, 1):
if istep != 0:
ax.clear()
PC = plt.pcolor(X, Y, C[istep,:,:])
PC.set_clim(0.,1.) # 着色範囲の固定 (ここでは0〜1)
# plt.pause(.01) # 1コマずつ確認
snap.append([PC])
ani = animation.ArtistAnimation(fig, snap)
ani.save('filename.gif',writer='XXX',fps=num1,dpi=num2)
}}
タイトルの変更がステップごとに反映されないため,時刻等を...
End:
*matplotlib 動画・アニメーション作成 [#ue24135e]
主な手法は2つらしい.~
加えて,imagemagick の convert を Python から使う方法もあ...
[[Matplotlib の pause を使ったアニメーションを簡単に動画...
個人的には画像で掃き出して動画は[[ ffmpeg >Linux/ffmpeg]]...
インポートは下記の通り.
#codeprettify(lang-python){{
import matplotlib.pyplot as plt
import matplotlib.animation as animation
}}
**animation.FuncAnimation [#z900e0e1]
ArtistAnimationは タイトルを動的に設定できない?ため,Fun...
このコマンドでは,各ステップに対応する描画 function を作...
また,その function の第一入力引数は,時間ステップを示す...
下記は pcolor で書いて,gif で保存するときのサンプル.
#codeprettify(lang-python){{
def update_pcolor(istep, ax, X, Y, pcdata, time_in_dateti...
PC = ax.pcolor(X, Y, pcdata[istep,:,:])
PC.set_clim([0.,1.])
ax.set_title(time_in_datetime[istep].strftime('%Y/%m/...
}}
#codeprettify(lang-python){{
def main():
fig = plt.figure()
ax = fig.add_subplot(111)
# とりあえず1回書いとく
PC = ax.pcolor(lon, lat, pcdata[0,:,:])
ax.axis('scaled')
ax.set_xlim(xmin, xmax)
ax.set_ylim(ymin, ymax)
cbar = fig.colorbar(PC)
cbar.ax.set_ylabel('colorbar label [unit]')
ax.set_yticks(yticks)
ax.set_xlabel('X-axis')
ax.set_ylabel('Y-axis')
ani = animation.FuncAnimation(fig, update_pcolor, far...
ani.save('filename.gif',writer='XXX')
}}
update_pcolor に xlabel 等を入れると毎回描くことになり時...
animation.FuncAnimation の2番目の入力引数には,function ...
その function(update_pcolor) の引数は,第二引数以降から f...
update_pcolor の第一引数は,frames の数にしたがって順番に...
frames=10 とすると,istep=0〜9 までのものを書く.~
interval で1フレーム当たりの表示時間(ms)を指定できる.
**animation.ArtistAnimation [#e81b2910]
plot や pcolor などの描画コマンドが返すものをステップごと...
#codeprettify(lang-python){{
fig = plt.figure()
ax = fig.add_subplot(111)
snap = []
for istep in np.arange(Nstart, Nend, 1):
if istep != 0:
ax.clear()
PC = plt.pcolor(X, Y, C[istep,:,:])
PC.set_clim(0.,1.) # 着色範囲の固定 (ここでは0〜1)
# plt.pause(.01) # 1コマずつ確認
snap.append([PC])
ani = animation.ArtistAnimation(fig, snap)
ani.save('filename.gif',writer='XXX',fps=num1,dpi=num2)
}}
タイトルの変更がステップごとに反映されないため,時刻等を...
Page:
Edit with a page name which already exists