python - 如何绘制动画图

标签 python pandas matplotlib graph ffmpeg

跟随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

最佳答案

很明显,你还没有安装ffmpeg (适本地)。它在安装过程中几乎看起来是一个权限问题?尝试卸载/清理ffmpeg并进行适当的重新安装。

我看到您正在尝试关注 “How to Create Animated Graphs in Python.”为什么不直接跳过 ffmpeg完全分开,只做一个plt.show()最后看动画。

关于python - 如何绘制动画图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55890848/

相关文章:

colors - 使用 matplotlib 指定轮廓的 RGB 颜色

python - matplotlib:可以改变背景颜色吗?

python - 使用深层复制复制类会导致无限递归

python - Django-registration 1.0 注册不起作用

python - 当列中的值发生变化时,在 Python 数据框中插入空白行?

python - 根据三列的值有条件地交互式计算列

python - legend() 如何处理动态数据集?

python - celery 倒计时错误

python - Python 中的矩阵逆

python - Spark 环境中的 pandas.read_csv (IBM Bluemix)