In [1]:
%matplotlib inline
import sys
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import animation, rc
from IPython.display import HTML
rc('animation', html='html5')

In [13]:
data = np.load('lord_of_rings_trajectory.npy')
data = data[0]
fig, ax = plt.subplots(figsize=(5, 5))

ax.set_xlim((-6, 6))
ax.set_ylim((-6, 6))

sca, = ax.plot(data[:, 0], data[:, 1], 'x')



In [18]:
def init():
    sca.set_data([], [])
    return (sca,)

def animate(i):
    x = data[:i*2, 0]
    y = data[:i*2, 1]
    sca.set_data(x, y)
    return (sca,)

anim = animation.FuncAnimation(fig, animate, init_func=init,
                               frames=1000, interval=20, blit=True)

In [19]:
anim.save('nice_lord_of_rings.mp4')

In [10]:
data = np.load('hmc_lord_of_rings.npy')
fig, ax = plt.subplots(figsize=(5, 5))

ax.set_xlim((-6, 6))
ax.set_ylim((-6, 6))

sca, = ax.plot([], [], 'x')



In [11]:
data = data[:5000, 0]

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

def animate(i):
    x = data[:i, 0]
    y = data[:i, 1]
    sca.set_data(x, y)
    return (sca,)

anim = animation.FuncAnimation(fig, animate, init_func=init,
                               frames=1000, interval=20, blit=True)

In [12]:
anim.save('hmc_lord_of_rings.mp4')

In [ ]: