Closed
Description
In order to realize an animation in IPython note book, I have run following code. (environment: Windows 7, Python 2.7.10, matplotlib 1.5.0, IPython 4.0.0)
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.animation as animation
fig = plt.figure()
x = np.arange(500)
frame_list = []
for a in range(10):
frame = plt.plot(x, a * x ** 2, lw=2)
frame_list.append(frame)
ani = animation.ArtistAnimation(fig, frame_list, interval = 500)
from IPython.display import HTML
HTML(ani.to_html5_video())
And this code raised an AttirubteError shown below.
AttributeError Traceback (most recent call last)
<ipython-input-7-ad3452685e20> in <module>()
13 ani = animation.ArtistAnimation(fig, frame_list, interval = 500)
14 from IPython.display import HTML
---> 15 HTML(ani.to_html5_video())
C:\Users\...\Documents\projects\science\.py27\lib\site-packages\matplotlib\animation.pyc in to_html5_video(self)
927 # Now open and base64 encode
928 with open(f.name, 'rb') as video:
--> 929 vid64 = base64.encodebytes(video.read())
930 self._base64_video = vid64.decode('ascii')
931 self._video_size = 'width="{0}" height="{1}"'.format(
AttributeError: 'module' object has no attribute 'encodebytes'
Although base64.encodebytes
is similar to base64.encodestring
, there is no such method in python2. Matplotlib doesn't support python2 now ?
Following code is my workaround for this problem.
import base64
try:
base64.encodebytes
except AttributeError:
base64.encodebytes = base64.encodestring
Metadata
Metadata
Assignees
Labels
No labels