title: how to save a pylab figure into in-memory file which can be read into PIL image?
body: <p>The following is my first shot which never works:</p>
  <pre><code>import cStringIO
  import pylab
  from PIL import Image
  pylab.figure()
  pylab.plot([1,2])
  pylab.title(&quot;test&quot;)
  buffer = cStringIO.StringIO()
  pylab.savefig(buffer, format='png')
  im = Image.open(buffer.read())
  buffer.close()
  </code></pre>
  <p>the error says,</p>
  <pre><code>Traceback (most recent call last):
    File &quot;try.py&quot;, line 10, in &lt;module&gt;
      im = Image.open(buffer.read())
    File &quot;/awesomepath/python2.7/site-packages/PIL/Image.py&quot;, line 1952, in open
      fp = __builtin__.open(fp, &quot;rb&quot;)
  </code></pre>
  <p>any ideas? I don't want the solution to involve extra packages.</p>