Savefig and StringIO using Agg

Hi, I am struggling to implement the equivalent of

    > to add
    > charting capacilities to a Plone content type. The example
    > uses PyChart, but I tried replacing the PyChart code with
    > matplotlib code. Here it is :

agg is already configured to write to a file object rather than a
filename. Is there anything that you can use that can be converted to
a file pointer? Eg, you can pass sys.stdout to savefig, unless
sys.stdout has been hijacked, which mod_python appears to do

Also, I do not recommend using the pylab interface in a web app
server. See

If anyone else has any ideas on how to get a StringIO-like object,
which exposes the file pointer interface needed by libpng, let me
know. This is what we are currently doing in extension code

  if (o.isString()) {
    std::string fileName = Py::String(o);
    const char *file_name = fileName.c_str();
    if ((fp = fopen(file_name, "wb")) == NULL)
      throw Py::RuntimeError( Printf("Could not open file %s", file_name).str() );
  else {
    if ((fp = PyFile_AsFile(o.ptr())) == NULL)
      throw Py::TypeError("Could not convert object to file pointer");
    fpclose = false;