質問編集履歴

1

別の例を追記

2022/08/31 03:18

投稿

Acy
Acy

スコア0

test CHANGED
File without changes
test CHANGED
@@ -57,6 +57,40 @@
57
57
  ![イメージ説明](https://ddjkaamml8q8x.cloudfront.net/questions/2022-08-31/8ce56c54-6120-4567-9be3-2af65a3b4f5b.png)
58
58
  ![イメージ説明](https://ddjkaamml8q8x.cloudfront.net/questions/2022-08-31/e0e5e61d-b7b3-4586-982a-bcdc5a19397d.png)
59
59
  ![イメージ説明](https://ddjkaamml8q8x.cloudfront.net/questions/2022-08-31/e1875f45-2b8c-4eab-813a-84b756efad29.png)
60
+
60
- ### 補足情報(FW/ツールのバージョンなど)
61
+ ### 補足情報
61
62
  JupyterLab3.3.2上でコーディングしています。
62
63
 
64
+ ### 追記
65
+ 以下の例でも試してみました。
66
+ frames[:10]のような30ではない数にすると、やはり不足した繰り返し分のフレームが重なってしまいました。![イメージ説明](https://ddjkaamml8q8x.cloudfront.net/questions/2022-08-31/b9a6917c-a449-4d27-a10a-a05896c863b0.gif)
67
+
68
+ ```python
69
+ #import packages
70
+ import matplotlib.pyplot as plt
71
+ import numpy as np
72
+ from matplotlib.animation import ArtistAnimation
73
+
74
+ x = np.linspace(0, np.pi * 4, 100)
75
+
76
+ fig, ax = plt.subplots(figsize=(4, 4))
77
+ frames = [] # 各フレームを構成する Artist 一覧
78
+ for delta in np.linspace(0, np.pi, 30):
79
+ y = np.sin(x + delta)
80
+
81
+ # 折れ線グラフを作成する。
82
+ lines = ax.plot(x, y, c='b')
83
+ title = ax.text(0.5, 1.01, 'delta={:.2f}'.format(delta),
84
+ ha='center', va='bottom',
85
+ transform=ax.transAxes, fontsize='large')
86
+ frames.append(lines + [title])
87
+
88
+ # アニメーションを作成する。
89
+ anim = ArtistAnimation(fig, frames[:10], interval=500)
90
+
91
+ # gif 画像として保存する。
92
+ anim.save('animation.gif', writer='imagemagick')
93
+ ```
94
+
95
+
96
+