Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
44
Help us understand the problem. What are the problem?

More than 5 years have passed since last update.

Pythonで簡単なアニメーションを描いてみる

デモ

output.gif

方法

ここではPythonのグラフ描画ライブラリmatplotlibanimation.ArtistAnimation関数を使います。流れとしては描画データの配列(ims)を用意し、その配列をanimation.ArtistAnimation関数の第2引数に渡すことでアニメーションを描画しています。

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

fig = plt.figure()
x = np.arange(0, 10, 0.1)

ims = []
for a in range(50):
    y = np.sin(x - a)
    im = plt.plot(x, y, "r")
    ims.append(im)

ani = animation.ArtistAnimation(fig, ims)
plt.show()

↓を加えるとアニメーションをgif形式で保存できます。

ani.save("hoge.gif")

参考

pythonで散布図アニメーションを試してみた
http://cflat-inc.hatenablog.com/entry/2014/03/17/214719

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
44
Help us understand the problem. What are the problem?