Remrinのpython攻略日記

python3に入門しました。python3についてあれこれとサンプルコードとか。

matplotlibでアニメーション

matplotlibでアニメーションを作ります。
  

# -*- coding: utf-8 -*-

import matplotlib.pyplot as plt
import matplotlib.animation as ani

def create_circle():
    c1 = plt.Circle((0, 0), 0.5)
    return c1

def update_radius(i, c1):  # i:フレーム番号
    plt.cla()
    c1.radius = i*0.5      # 最大半径15
    return c1,

def create_animation():
    fig = plt.gcf()
    ax = plt.axes(xlim=(-10, 10), ylim=(-10, 10))
    ax.set_aspect("equal")
    c1 = create_circle()
    ax.add_patch(c1)
    anim = ani.FuncAnimation(fig, update_radius, 
                        fargs=(c1,), frames=30, interval=50)
    anim.save("circle.gif", writer = 'imagemagick')
create_animation()

 
円が徐々に大きくなるアニメーションになるはずが、
ValueError: Cannot save animation: no writers are available. Please install ffmpeg to save animations.
というエラーが出てうまくいきませんでした。
imagemagickをダウンロードして、matplotlibrcのanimation convert pathを
#animation.convert_path: C:\py3531\pytemp\ImageMagick-7.0.5-5-portable-Q16-x86\magick.exeとしましたが認識せず。
また時間のある時にでも調べてみます。