Saving a figure toStringIO or similar

Using the agg backend you can obtain an RGBA buffer or RGB

    >> string which can then be loaded as a PIL Image for processing.
    >> I've adapted a the examples/ to demonstrate.

    > Thanks a lot, Nicolas! Excellent... no more temp file! It
    > took me some time to figure out how to get the PNG image
    > data from PIL, but it worked out quite well.

Could you post a complete example so that others won't have to spend
that extra time figuring out how to put all the pieces together?