Renderer problems using Matplotlib from within a script
Question: I've narrowed down to this call:

    
    
    fig.canvas.tostring_argb() #fig=matplotlib.pyplot.figure()
    

this function raises an `AttributeError` when I run the code as a python
script. `AttributeError: 'FigureCanvasGTKAgg' object has no attribute
'renderer'`

However, this code works properly if run in the `ipython --pylab` command
line.

As far as I can tell from the documentation, the Agg renderer should work OK.

The context is that I'm trying to make a movie from figures, without saving
the frames to disk; as per [this
question](http://stackoverflow.com/questions/4092927/generating-movie-from-
python-without-saving-individual-frames-to-files). 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.

Is there some configuration setting I can make to get matplotlib to work
correctly from within a script?

_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'
    


Answer: I suspect that you have missed out the call to:

    
    
    fig.canvas.draw()
    

before

    
    
    fig.canvas.tostring_argb()
    

as

    
    
    import matplotlib
    matplotlib.use('Agg')
    import matplotlib.pyplot
    fig=matplotlib.pyplot.figure()
    fig.canvas.tostring_argb()
    

fails for me, but

    
    
    import matplotlib
    matplotlib.use('Agg')
    import matplotlib.pyplot
    fig=matplotlib.pyplot.figure()
    fig.canvas.draw()
    fig.canvas.tostring_argb()
    

works.

