OSError:[Errno 22]参数无效,将动画保存到文件时出错

时间:2017-10-04 10:45:51

标签: python numpy animation matplotlib

我使用jupyter笔记本编写代码,然后使用HTML(anim.to_html5_video()) 在笔记本上显示我的答案gif。但它总是有一个不好的问题。这是一个例子:

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())

错误是:

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.

0 个答案:

没有答案