在脚本中使用Matplotlib的渲染器问题 [英] Renderer problems using Matplotlib from within a script
问题描述
我已经把这个范围缩小了:
I've narrowed down to this call:
fig.canvas.tostring_argb() #fig=matplotlib.pyplot.figure()
当我将代码作为 python 脚本运行时,这个函数会引发一个 AttributeError
. AttributeError:'FigureCanvasGTKAgg'对象没有属性'renderer'
this function raises an AttributeError
when I run the code as a python script.
AttributeError: 'FigureCanvasGTKAgg' object has no attribute 'renderer'
但是,如果在 ipython --pylab
命令行中运行,此代码可以正常工作.
However, this code works properly if run in the ipython --pylab
command line.
据我所知,Agg 渲染器应该可以正常工作.
As far as I can tell from the documentation, the Agg renderer should work OK.
上下文是我试图用数字制作电影,而不保存帧到磁盘;按照此问题.我正在使用流像素阵列的方法到 ffmpeg
(作为一个单独的进程运行)来执行此操作,我需要框架的值的 argb
数组.
The context is that I'm trying to make a movie from figures, without saving the frames
to disk; as per this question. I'm using the approach that streams the pixel arrays
to ffmpeg
(running as a separate process) to do this, I need the argb
array of values from the frame.
是否可以进行一些配置设置,以使matplotlib在脚本中正常工作?
Is there some configuration setting I can make to get matplotlib to work correctly from within a script?
编辑根据评论尝试 use('Agg')
;仍然失败;这是一个最小的工作示例.
Edit
Tried use('Agg')
as per a comment; still fails; this is a minimal working example.
[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'
推荐答案
我最终安装并使用了 WXAgg
后端;Agg
和默认的 GTKAgg
对我不起作用.
I ended up installing and using the WXAgg
backend; the Agg
,and default GTKAgg
, didn't work for me.
这篇关于在脚本中使用Matplotlib的渲染器问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!