pyplot_animation

In [1]:
%matplotlib inline

import matplotlib.pyplot as plt
import numpy as np
from matplotlib import animation as ani
import seaborn as sns

num_frame = 80.
x_range= 7

def animate(nframe):
    # global num_frame
    plt.clf()
    a = ((5*nframe/num_frame) -.5) * np.pi
    x = np.linspace(-x_range, x_range, 200)
    y = np.sin(x+a)

    plt.xlim(-x_range, x_range)
    plt.ylim(-1.1,1.1)
    plt.plot(x, y, c="b")

fig = plt.figure(figsize=(12,5))
anim = ani.FuncAnimation(fig, animate, frames=int(num_frame))#, blit=True)
anim.save('anim_test.gif', writer='imagemagick', fps=5, dpi=64)
../../../_images/contents_notebooks_matplotlib_pyplot_animation_1_0.png