matplotlib.animation を使用せず、matplotlib.pyplot で描画しては消して、という方法でアニメーションを作成しました。
(実際のコードを見ていただいた方が意図を理解しやすいと思います。)
出力結果を動画として保存するにはどのようにすれば良いでしょうか。
そのような方法がありましたら、教えていただきたいです。
Python
1#!/usr/bin/env python3 2 3import matplotlib.pyplot as plt 4import numpy as np 5 6show_animation = True 7 8 9def update(x): 10 x[0] += 0.1 11 x[1] += 0.0 12 return x 13 14 15def main(): 16 print(__file__ + 'Start!') 17 18 # initialization 19 p_start = np.array([0.0, 2.0]) 20 p_goal = np.array([10.0, 2.0]) 21 22 x = np.array([0.0, 2.0]) 23 24 while True: 25 # update 26 x = update(x) 27 28 if show_animation: 29 plt.cla() 30 31 plt.gcf().gca().set_aspect('equal') 32 plt.grid(True) 33 plt.xlim(-0.5, 10.5) 34 plt.ylim(-0.5, 4.5) 35 36 plt.plot(p_start[0], p_start[1], '.r', markersize=12) 37 plt.plot(p_goal[0], p_goal[1], '.b', markersize=12) 38 39 plt.plot(x[0], x[1], '^g') 40 41 plt.pause(0.001) 42 43 if x[0] >= 10: 44 print('Goal!') 45 break 46 47 plt.show() 48 49 50if __name__ == '__main__': 51 main() 52

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/03/31 18:11