print_figure(), savefig() and file-like objects

I just updated to work with the latest version of pycairo.
The cairo backend can now output PNG, PDF, PS and SVG to a filename or a
file-like object.

However, print_figure() does not support writing to file objects in
different formats because it only takes a 'filename' argument and does not
have an argument to allow you to specify the format.
If the filename is string-like it writes to the filename (and the format is
often encoded into the string, as in 'file.png' for example)
If the filename is not string-like the backend has no way to know which
format is required and has to choose a default format (agg defaults to PNG).

I think print_figure() should be changed from
    print_figure (filename, ...)
    print_figure (filename, format='png', ...)
    where format is in ('png', 'ps', 'svg') etc
And savefig() would need a corresponding change.

This would allow backends to write to file-like objects in the requested
format. For example, you could then write to a file-like object in SVG format.

Any comments?


Send instant messages to your online friends