I use jupyter notebook to write my code, and I use HTML(anim.to_html5_video())
to show my answer gif on the notebook. But it always have a bad problem. Here is an example:
import numpy
import seaborn
from matplotlib import pylab as plt
from matplotlib import animation
from IPython.display import HTML
nx=40
nt=25
dx=2/(nx-1)
dt=.025
c=1
u=numpy.ones(nx)
u[int(.5/dx):int(1/dx+1)]=2
uu=numpy.ones(nx)
fig=plt.figure(figsize=(8,5))
ax = plt.axes(xlim=(0,2), ylim=(1,2))
plt.xticks(fontsize=14)
plt.yticks(fontsize=14)
line = ax.plot([], [], color='#003366', ls='-', lw=3)[0]
def convection(i):
x=numpy.linspace(0,2,nx)
line.set_data(x,u)
uu=u.copy()
u[1:]=uu[1:]-c*dt/dx*(uu[1:]-uu[0:-1])
anim = animation.FuncAnimation(fig, convection,frames=nt, interval=100)
HTML(anim.to_html5_video())
The error is:
OSError Traceback (most recent call last)
OSError: [Errno 22] Invalid argument
During handling of the above exception, another exception occurred:
OSError: Error saving animation to file (cause: [Errno 22] Invalid argument)
Stdout: b'' StdError: b"Unknown encoder 'h264'\r\n". It may help to re-run
with --verbose-debug.