Looking for a way to save a graph

Hello,

I would like to save a matplotlib figure (data, title and axes label,
plot properties, ...) to load it later on for modification. Something
like figure.savelall("file.matplot") and later on do a
figure.loadall("file.matplot") using an empty figure.

Did somebody already implement such a functionality?
If yes Is it available somewhere or are you eager to share it?

Thanks,

David

I am but a humble newbie, but why not simply take your figure
object/reference and Pickle it (see
http://docs.python.org/lib/module-pickle.html)?

···

On Thu, August 23, 2007 5:33 pm, David Tremouilles wrote:

I would like to save a matplotlib figure (data, title and axes label,
plot properties, ...) to load it later on for modification. Something
like figure.savelall("file.matplot") and later on do a
figure.loadall("file.matplot") using an empty figure.

--
Alex Pounds (Creature) .~. http://www.alexpounds.com/
                                        /V\ http://www.ethicsgirls.com/
                                       // \\
"Variables won't; Constants aren't" /( )\
                                       ^`~'^

Reasonable request, reasonable solution, but alas neither will work.
The mpl extension code doesn't support pickling.

JDH

···

On 8/23/07, Alex Pounds <alex@...1705...> wrote:

On Thu, August 23, 2007 5:33 pm, David Tremouilles wrote:
> I would like to save a matplotlib figure (data, title and axes label,
> plot properties, ...) to load it later on for modification. Something
> like figure.savelall("file.matplot") and later on do a
> figure.loadall("file.matplot") using an empty figure.

I am but a humble newbie, but why not simply take your figure
object/reference and Pickle it (see
http://docs.python.org/lib/module-pickle.html)?

Alex Pounds wrote:

···

On Thu, August 23, 2007 5:33 pm, David Tremouilles wrote:

I would like to save a matplotlib figure (data, title and axes label,
plot properties, ...) to load it later on for modification. Something
like figure.savelall("file.matplot") and later on do a
figure.loadall("file.matplot") using an empty figure.

I am but a humble newbie, but why not simply take your figure
object/reference and Pickle it (see
http://docs.python.org/lib/module-pickle.html)?

Won't work. Pickling only works for objects that have been designed for it. Such design is not trivial for extension code, and has not been done for mpl.

Eric

>
> I am but a humble newbie, but why not simply take your figure
> object/reference and Pickle it (see
> http://docs.python.org/lib/module-pickle.html)?
>

Won't work. Pickling only works for objects that have been designed for
it. Such design is not trivial for extension code, and has not been
done for mpl.

I keep coming back to this from time-to-time and have a go a poking
around in the mpl codebase but I've never figured out exactly what state
the matplotlib "Lazy Values" and "BinOps" store.

If this internal state could be retrieved and then later restored, then
python can pickle the extension objects using the copy-reg module. It
might be enough if methods were added to the BinOp objects to retrieve
internal objects to which they link. You could then recursively walk
through the whole lazy-value tree. To make this work, you would need to
retrieve the underlying C++ objects with it's python wrapper object
intact (i.e. with the same IDs) so that python references to that object
created elsewhere still work.

While the concept of Lazy Values is easy enough to understand,
understanding how and where these objects fit in to the MPL architecture
is hard. I think a little documentation or explanation of this could go
a long way to helping implement this. If I could understand all the
places the Lazy Values are used, I'm keen to attempt the implementation
of pickle-ability. One problem for me is my C++ knowledge is ~ 0.

BC

···

Eric

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/

OK I see... nothing straightforward...

Best way for me is maybe to implement such a system myself:
The system would collect the information to be saved by kind of
introspection of the figure.
I'm planning to save data and plot properties in an hdf5 file. Kind of
inverted process will be used to restore the figure.
Of course I will not cover the whole possible figure case but only
what I'm currently using for my work.
If somebody did similar work and is eager to share or
if somebody have any suggestion please let me know.

Thanks for the great matplotlib and to its community !

Regards,

David

A huge +1 for this approach. Pickle is NOT meant to be a persistent,
on-disk file format, but rather a way to serialize the *current* state
of an object in memory. Emphasis on current: if you unpickle an old
pickle in an environment where the class layout of your object (or any
object the parent holds a reference to) has changed, the unpickling
fails, completely and irrecoverably.

As someone who has already had to write pickle loader functions to
salvage old pickles (because computing them had been very expensive),
I've learned my lesson. Pickle works well as a way to quickly
dump/load data that is either made up of simple python types *only*
(since they don't change often) or for objects that you have good
reason to expect won't be changing their API while you care about the
pickles.

But pickling is NOT a 'data format', and using it as such will
inevitably lead to much pain and suffering. HDF5 *is* a data format.
In our project we precisely went to hdf5 instead of pickling.

Cheers,

f

···

On 8/24/07, David Tremouilles <david.trem@...287...> wrote:

OK I see... nothing straightforward...

Best way for me is maybe to implement such a system myself:
The system would collect the information to be saved by kind of
introspection of the figure.
I'm planning to save data and plot properties in an hdf5 file. Kind of
inverted process will be used to restore the figure.
Of course I will not cover the whole possible figure case but only
what I'm currently using for my work.
If somebody did similar work and is eager to share or
if somebody have any suggestion please let me know.

Hello,
I was looking for save functionality of the list, and I've read your
post. Did you managed to write such a system? Could you please share it,
I would like to be able to save a figure in order to modify later on its
properties (line thickness, title, axes, etc...)

Thanks

···

Le vendredi 24 août 2007 à 11:30 +0200, David Tremouilles a écrit :

OK I see... nothing straightforward...

Best way for me is maybe to implement such a system myself:
The system would collect the information to be saved by kind of
introspection of the figure.
I'm planning to save data and plot properties in an hdf5 file. Kind of
inverted process will be used to restore the figure.
Of course I will not cover the whole possible figure case but only
what I'm currently using for my work.
If somebody did similar work and is eager to share or
if somebody have any suggestion please let me know.