【发布时间】:2013-12-01 19:15:24
【问题描述】:
我已经缩小到这个电话:
fig.canvas.tostring_argb() #fig=matplotlib.pyplot.figure()
当我将代码作为 python 脚本运行时,此函数会引发 AttributeError。
AttributeError: 'FigureCanvasGTKAgg' object has no attribute 'renderer'
但是,如果在ipython --pylab 命令行中运行,此代码可以正常工作。
据我从文档中得知,Agg 渲染器应该可以正常工作。
上下文是我正在尝试从人物制作电影,而不保存帧
到磁盘;根据this question。我正在使用流式传输像素阵列的方法
到ffmpeg(作为一个单独的进程运行)要做到这一点,我需要来自框架的argb数组值。
我可以进行一些配置设置以使 matplotlib 在脚本中正常工作吗?
编辑
根据评论尝试use('Agg');仍然失败;这是一个最小的工作示例。
[dave@dave tools]$ python -c "import matplotlib; matplotlib.use('Agg'); import matplotlib.pyplot; fig=matplotlib.pyplot.figure(); fig.canvas.tostring_argb()"
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/lib64/python2.7/site-packages/matplotlib/backends/backend_agg.py", line 416, in tostring_argb
return self.renderer.tostring_argb()
AttributeError: FigureCanvasAgg instance has no attribute 'renderer'
【问题讨论】:
-
将
matplotlib.use('Agg')放在脚本的顶部。问题是您正在尝试使用 gui 后端而没有正确设置它。如果您能生成一个 10 行的脚本来演示您的问题,那就更好了。
标签: python matplotlib