In [1]:
%matplotlib inline

In [2]:
import numpy as np
import matplotlib.pyplot as plt

from matplotlib import animation, rc
from IPython.display import HTML

In [3]:
!sudo pip3 install --upgrade matplotlib


The directory '/home/cloud/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/cloud/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Requirement already up-to-date: matplotlib in /usr/local/lib/python3.5/dist-packages (3.0.2)
Requirement already satisfied, skipping upgrade: python-dateutil>=2.1 in /usr/local/lib/python3.5/dist-packages (from matplotlib) (2.7.3)
Requirement already satisfied, skipping upgrade: cycler>=0.10 in /usr/local/lib/python3.5/dist-packages (from matplotlib) (0.10.0)
Requirement already satisfied, skipping upgrade: numpy>=1.10.0 in /usr/local/lib/python3.5/dist-packages (from matplotlib) (1.14.3)
Requirement already satisfied, skipping upgrade: kiwisolver>=1.0.1 in /usr/local/lib/python3.5/dist-packages (from matplotlib) (1.0.1)
Requirement already satisfied, skipping upgrade: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in /usr/local/lib/python3.5/dist-packages (from matplotlib) (2.2.0)
Requirement already satisfied, skipping upgrade: six>=1.5 in /usr/local/lib/python3.5/dist-packages (from python-dateutil>=2.1->matplotlib) (1.11.0)
Requirement already satisfied, skipping upgrade: setuptools in /usr/local/lib/python3.5/dist-packages (from kiwisolver>=1.0.1->matplotlib) (38.5.1)

In [4]:
!sudo pip3 install --upgrade cycler


The directory '/home/cloud/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/cloud/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Requirement already up-to-date: cycler in /usr/local/lib/python3.5/dist-packages (0.10.0)
Requirement already satisfied, skipping upgrade: six in /usr/local/lib/python3.5/dist-packages (from cycler) (1.11.0)

In [5]:
import matplotlib as mpl
print(mpl.__version__)


3.0.2

In [6]:
# First set up the figure, the axis, and the plot element we want to animate
fig, ax = plt.subplots()

ax.set_xlim(( 0, 2))
ax.set_ylim((-2, 2))

line, = ax.plot([], [], lw=2)



In [7]:
# initialization function: plot the background of each frame
def init():
    line.set_data([], [])
    return (line,)

In [8]:
# animation function. This is called sequentially
def animate(i):
    x = np.linspace(0, 2, 1000)
    y = np.sin(2 * np.pi * (x - 0.01 * i))
    line.set_data(x, y)
    return (line,)

In [9]:
# call the animator. blit=True means only re-draw the parts that have changed.
anim = animation.FuncAnimation(fig, animate, init_func=init,
                               frames=100, interval=20, blit=True)

In [10]:
HTML(anim.to_html5_video())


Out[10]:

In [11]:
# equivalent to rcParams['animation.html'] = 'html5'
rc('animation', html='html5')

In [12]:
anim


Out[12]:

In [ ]:


In [ ]: