Piddling Pertinent
  • Home
  • Categories
  • Tags
  • Archives

#AcademicValentines

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]:
Your browser does not support the video tag.

Share on: Twitter ❄ Facebook ❄ Google+ ❄ Email

Comments
comments powered by Disqus

Related Posts

  • Expectation Maximisation in Python: Coin Toss Example
  • Animated Heart in Python
  • Andrews Curves
  • Expected number of flips in a memoryless concentration game
  • Fourier transform and choice of window function

  • « Animated Heart in Python
  • Andrews Curves »

Published

Feb 15, 2018

Category

misc

Tags

  • animation 2
  • python 6

Contact

  • Piddling Pertinent - trivially relevant
  • Powered by Pelican. Theme: Elegant