import matplotlib.pyplot as plt
from matplotlib import animation
import numpy as np
fig, ax = plt.subplots()
x = np.arange(0, 2*np.pi, 0.01)
line, = ax.plot(x, np.sin(x))
def animate(i):
line.set_ydata(np.sin(x + i/10.0)) # update the data
return line,
# Init only required for blitting to give a clean slate.
def init():
line.set_ydata(np.ma.array(x, mask=True))
return line,
anim = animation.FuncAnimation(fig, animate, np.arange(1, 200), init_func=init, interval=25, blit=True)
filename = 'animation.webm'
anim.save(filename, fps=6, extra_args=['-vcodec', 'libvpx'])
Which is in the path of the current directory we're in. Then we use it to construct the URL to the video file.
import os
dirs = os.getcwd().split('/')
project_id = dirs[2]
path = '/'.join(dirs[3:])
url = "/{project_id}/raw/{path}/{filename}".format(**locals())
print(url)
from IPython.display import HTML
HTML('''<video autoplay controls loop>
<source src="{url}" type="video/webm">
</video>'''.format(url = url))