In [2]:
# Credits: http://www.walkingrandomly.com/?p=5964 
# and http://jakevdp.github.io/blog/2013/05/19/a-javascript-viewer-for-matplotlib-animations/
import warnings
warnings.filterwarnings('ignore')
import matplotlib.pyplot as plt
from matplotlib import animation
import numpy as np
from JSAnimation import IPython_display


fig = plt.figure()
ax = plt.axes(xlim=(-2, 2), ylim=(-2, 2))
line, = ax.plot([], [], lw=2, color='red')

def init():
    line.set_data([], [])
    return line,

def animate(i):
    x = np.linspace(-2, 2, 1000)
    y = (np.sqrt(np.cos(x))*np.cos(i*x)+np.sqrt(np.abs(x))-0.7)*(4-x*x)**0.01
    line.set_data(x, y)
    return line,

animation.FuncAnimation(fig, animate, init_func=init,
                        frames=100, interval=30)
Out[2]:


Once Loop Reflect