如何绘制动画图形

2024-09-25 08:40:34 发布

您现在位置:Python中文网/ 问答频道 /正文

沿着How to Create Animated Graphs in Python当构建动画情节时,在编写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

Tags: nameinimportdatatitlematplotlibas错误
1条回答
网友
1楼 · 发布于 2024-09-25 08:40:34

显然,您还没有正确安装ffmpeg。在安装过程中看起来几乎是权限问题?尝试卸载/清除ffmpeg并进行正确的重新安装。你知道吗

我知道你在试着跟随“How to Create Animated Graphs in Python.”为什么不跳过ffmpeg部分,在最后做一个plt.show()来看看动画呢。你知道吗

相关问题 更多 >