如何绘制动画图

时间:2019-04-28 13:42:49

标签: python pandas matplotlib graph ffmpeg

我正在构造一个动画情节,在编写ffmpeg时出现以下错误:

'Requested MovieWriter ({}) not available'.format(name))
RuntimeError: Requested MovieWriter (ffmpeg) not available

收到此错误后,我最初尝试通过以下方法使用pip安装ffmpeg:

python -m install ffmpeg

似乎已经成功安装了ffmpeg,但是回到我的代码,我仍然遇到相同的错误

在我的代码下面找到:

import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib
import matplotlib.pyplot as plt
import matplotlib.animation as animation

overdoses = pd.read_excel(r'C:\Users\ACER\Desktop\overdose_data_1999-2015.xls',sheet_name='Online',skiprows =6)

def get_data(table,rownum,title):
    data = pd.DataFrame(table.loc[rownum][2:]).astype(float)
    data.columns = {title}
    return data

title = 'Heroin Overdoses'
d = get_data(overdoses,18,title)
x = np.array(d.index)
y = np.array(d['Heroin Overdoses'])
overdose = pd.DataFrame(y,x)
overdose.columns = {title}
Writer = animation.writers['ffmpeg']

这是堆栈跟踪:

Traceback (most recent call last):
  File "C:\Python\Python36\lib\site-packages\matplotlib\animation.py", line 161, in __getitem__
    return self.avail[name]
KeyError: 'ffmpeg'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<pyshell#18>", line 1, in <module>
    Writer = animation.writers['ffmpeg']
  File "C:\Python\Python36\lib\site-packages\matplotlib\animation.py", line 164, in __getitem__
    'Requested MovieWriter ({}) not available'.format(name))
RuntimeError: Requested MovieWriter (ffmpeg) not available

1 个答案:

答案 0 :(得分:0)

很显然,您尚未正确安装ffmpeg。在安装过程中几乎看起来是权限问题?尝试卸载/清理ffmpeg,然后重新安装。

我看到您正在尝试遵循“How to Create Animated Graphs in Python.”,为什么不完全跳过ffmpeg部分,而只是在最后做一个plt.show()来观看动画呢。