In [1]:
# Credits: http://www.walkingrandomly.com/?p=5964
import warnings
warnings.filterwarnings('ignore')
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
sns.set_style('white')
from matplotlib.animation import FuncAnimation
from IPython.display import HTML
fig = plt.figure()
ax = plt.axes(xlim=(-2, 2),
ylim=(-2, 2))
line, = ax.plot([], [],
lw=2,
color='red')
time_text1 = ax.text(-0.5, 1.5,
"I've read",
fontsize=18,
color='black')
time_text2 = ax.text(-0.5, -1.7,
"your work!",
fontsize=18,
color='black')
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)
time_text1.set_position([-np.sin(i/8.0)-0.25,1.5])
time_text2.set_position([-np.sin(i/8.0)-0.25,-1.7])
return line,
sns.despine()
animation = FuncAnimation(fig, animate,
init_func=init,
frames=120,
interval=25)
HTML(animation.to_html5_video())
Out[1]:
comments powered by Disqus