re ndered objects (esp. SVG)

[Fairly new at matplotlib, but very happy with it so far]

Is it possible to retrieve images rendered by one of the backends as an
object, rather than just saving to a file?

Specifically, I need to render graphs to SVG code, that I can turn into a
DOM object for further manipulation. I can save to a temp file and
immediately reload it into a DOM, but that is cumbersome in a single
program.

The only place I can see to generate rendered output is savefig(). There is
a reference in the documentation to using a file-like object with the Cairo
backend. Is that the only possibility?

If so, any ideas on a workaround other than temp files?

···

--
View this message in context: http://www.nabble.com/rendered-objects-(esp.-SVG)-tf4952354.html#a14180802
Sent from the matplotlib - users mailing list archive at Nabble.com.

[I only seem to be getting this message from the list today, despite the timestamp of 2007-12-05. Sorry for the delay.]

As of matplotlib 0.91.1, savefig() supports saving to a file-like object for most backends (excluding Gtk and Wx). You can pass in a StringIO object to savefig for instance, and then pass its content to the XML parser of your choice. (There is no way to get DOM objects directly, since the SVG backend actually writes the XML content directly as a stream of bytes).

You can specify SVG as your output by either setting the backend appropriately or passing a "format" kwarg to savfig, e.g.

   savefig(fileobj, format="svg")

Cheers,
Mike

bplewe wrote:

···

[Fairly new at matplotlib, but very happy with it so far]

Is it possible to retrieve images rendered by one of the backends as an
object, rather than just saving to a file?

Specifically, I need to render graphs to SVG code, that I can turn into a
DOM object for further manipulation. I can save to a temp file and
immediately reload it into a DOM, but that is cumbersome in a single
program.

The only place I can see to generate rendered output is savefig(). There is
a reference in the documentation to using a file-like object with the Cairo
backend. Is that the only possibility?

If so, any ideas on a workaround other than temp files?

--
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA

I should add that in 0.91.1, you'll be hit by this bug:

http://sourceforge.net/mailarchive/message.php?msg_name=475ED00A.400%40stsci.edu

You can wait for 0.91.2, or patch your cbook.py as suggested by Brandon in the above thread.

Cheers,
Mike

Michael Droettboom wrote:

···

[I only seem to be getting this message from the list today, despite the timestamp of 2007-12-05. Sorry for the delay.]

As of matplotlib 0.91.1, savefig() supports saving to a file-like object for most backends (excluding Gtk and Wx). You can pass in a StringIO object to savefig for instance, and then pass its content to the XML parser of your choice. (There is no way to get DOM objects directly, since the SVG backend actually writes the XML content directly as a stream of bytes).

You can specify SVG as your output by either setting the backend appropriately or passing a "format" kwarg to savfig, e.g.

   savefig(fileobj, format="svg")

Cheers,
Mike

bplewe wrote:

[Fairly new at matplotlib, but very happy with it so far]

Is it possible to retrieve images rendered by one of the backends as an
object, rather than just saving to a file?

Specifically, I need to render graphs to SVG code, that I can turn into a
DOM object for further manipulation. I can save to a temp file and
immediately reload it into a DOM, but that is cumbersome in a single
program.

The only place I can see to generate rendered output is savefig(). There is
a reference in the documentation to using a file-like object with the Cairo
backend. Is that the only possibility?

If so, any ideas on a workaround other than temp files?

--
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA