save or pickle figure object

Hi folks,
  I would like to save preliminary figures for later processing and refinement with matplotlib. Is there a way to save or pickle a figure object and later reload it. Matlab has a feature like that and and I was wondering if matplotlib has it too.

Thanks a lot,

  Josef

···

--

Josef Koller (TSPA/Correspondence)
Space Science and Applications, ISR-1, MS D466
Los Alamos National Laboratory, NM 87545-1663
Phone: (505) 665 3399 http://www.koller.info
Fax: (505) 665 7395 email jkoller@...652...

No, it doesn't exist. We've taken a stab at it once or twice, but
have been stymied because we make extensive use of a python extension
libray CXX, and these objects have resisted our attempts to pickle
them. With our recent transforms refactoring, which removes the
hairiest CXX dependency, it may be worth taking another look, but
noone is currently working on it.

JDH

···

On Tue, Sep 16, 2008 at 5:06 PM, Josef Koller <jkoller@...652...> wrote:

Hi folks,
I would like to save preliminary figures for later processing and
refinement with matplotlib. Is there a way to save or pickle a figure
object and later reload it. Matlab has a feature like that and and I was
wondering if matplotlib has it too.

John Hunter wrote:

···

On Tue, Sep 16, 2008 at 5:06 PM, Josef Koller <jkoller@...652...> wrote:

Hi folks,
I would like to save preliminary figures for later processing and
refinement with matplotlib. Is there a way to save or pickle a figure
object and later reload it. Matlab has a feature like that and and I was
wondering if matplotlib has it too.

No, it doesn't exist. We've taken a stab at it once or twice, but
have been stymied because we make extensive use of a python extension
libray CXX, and these objects have resisted our attempts to pickle
them. With our recent transforms refactoring, which removes the
hairiest CXX dependency, it may be worth taking another look, but
noone is currently working on it.

My sense, based on very little experience, is that pickles of complicated objects are very fragile, so even if we could pickle figures, I fear it might cause more trouble ("I can't load this absolutely critical figure I pickled 6 months ago") than it would be worth.

Eric

Hi folks,
I would like to save preliminary figures for later processing and
refinement with matplotlib. Is there a way to save or pickle a figure
object and later reload it. Matlab has a feature like that and and I was
wondering if matplotlib has it too.

Thanks a lot,

Josef

As you've already been told, you can't pickle/shelve mpl objects. Our
solution to this is to have a native python shadow object that
contains all the bits and pieces needed to create a figure, and always
build the plots from these shadow objects. This gives us the
advantage of being able to shelve the shadow objects and rebuild the
figures later. Of course, we're doing this in context of a large
program using the mpl api, so if you're just using pylab, you're a bit
SOL.

···

On Tue, Sep 16, 2008 at 3:06 PM, Josef Koller <jkoller@...652...> wrote:

Hi Anthony,

As you've already been told, you can't pickle/shelve mpl objects. Our
solution to this is to have a native python shadow object that
contains all the bits and pieces needed to create a figure, and always
build the plots from these shadow objects. This gives us the
advantage of being able to shelve the shadow objects and rebuild the
figures later.

this is rather interesting !
any code to point to ?

cheers,
sebastien.

···

--
###################################
# Dr. Sebastien Binet
# Lawrence Berkeley National Lab.
# 1 Cyclotron Road
# Berkeley, CA 94720
###################################

Hi Anthony,

As you've already been told, you can't pickle/shelve mpl objects. Our
solution to this is to have a native python shadow object that
contains all the bits and pieces needed to create a figure, and always
build the plots from these shadow objects. This gives us the
advantage of being able to shelve the shadow objects and rebuild the
figures later.

this is rather interesting !
any code to point to ?

Hi Sebastien,

I'll see what I can extract from the code tomorrow at work. It's
pretty modular so I should be able to point to something.

···

On Tue, Sep 16, 2008 at 8:17 PM, Sebastien Binet <hep.sebastien.binet@...287...> wrote:

We have some experience maintaining persistent object storage over long
periods of time. The best solution we've found is to do something like
this:

- create a read/write method on each class. Every class that needs to be
stored must have this. This includes class you would store (eg Figure) and
things that are member variables of those classes.

- Each class stores a version number along with it's data which represents
the version of the persistent representation for that class. So each class
has its own, internal versioning scheme that represents a specific set of
variables with specific types.

- The read method on each class must check the version number and then read
the appropriate data for that version of itself. Whenever the persistent
representation of the class changes (usually if the member variables
change), you increment the version number. Implicit in this is that if you
change the member variables of a class, the class read method must be able
to convert the variables that existed in the older version of itself into
the new member variables (since that's what the new methods on that class
will be using)

FYI It is possible to use pickle to do this but you can't rely on pickle to
automatically save the member dictionary. You need to implement
__getstate__ and __setstate__ and have them incorporate a version number in
the dictionary they return. In addition, you shouldn't blindly save every
member variable. If member variables can be constructed in terms of other
data, it may be better to store that data and then reconstruct the member
variables in the __setstate__ method.

Using this type of system, you get a hierarchy of objects that each have
their own, internal versioning system. This lets you make changes to a
single class, increment it's version, and update its save/load methods and
it won't affect any other part of the system and still retains backwards
reading capability.

Ted

···

-----Original Message-----
From: matplotlib-users-bounces@lists.sourceforge.net
[mailto:matplotlib-users-bounces@lists.sourceforge.net] On Behalf Of
Eric Firing
Sent: Tuesday, September 16, 2008 7:04 PM
To: John Hunter
Cc: Josef Koller; matplotlib-users@lists.sourceforge.net
Subject: Re: [Matplotlib-users] save or pickle figure object

John Hunter wrote:
> On Tue, Sep 16, 2008 at 5:06 PM, Josef Koller <jkoller@...652...> > wrote:
>> Hi folks,
>> I would like to save preliminary figures for later processing and
>> refinement with matplotlib. Is there a way to save or pickle a
figure
>> object and later reload it. Matlab has a feature like that and and I
was
>> wondering if matplotlib has it too.
>
> No, it doesn't exist. We've taken a stab at it once or twice, but
> have been stymied because we make extensive use of a python extension
> libray CXX, and these objects have resisted our attempts to pickle
> them. With our recent transforms refactoring, which removes the
> hairiest CXX dependency, it may be worth taking another look, but
> noone is currently working on it.

My sense, based on very little experience, is that pickles of
complicated objects are very fragile, so even if we could pickle
figures, I fear it might cause more trouble ("I can't load this
absolutely critical figure I pickled 6 months ago") than it would be
worth.

Eric

-----------------------------------------------------------------------
--
This SF.Net email is sponsored by the Moblin Your Move Developer's
challenge
Build the coolest Linux based applications with Moblin SDK & win great
prizes
Grand prize is a trip for two to an Open Source event anywhere in the
world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Checked by AVG - http://www.avg.com
Version: 8.0.169 / Virus Database: 270.6.21/1674 - Release Date:
9/16/2008 8:15 AM

Josef,
I too have been interested in such a feature for matplotlib and have
made some (albeit lame) stabs at finding a solution. I started a
project on google code that has some very limited capacity to save line
plots and the necessary data arrays from matplotlib into an hdf5 file for later processing. It is by
no means a complete solution but may serve as a VERY rough model to add
this functionality. It was my hope that if you could capture the
underlying keyword arguments necessary to recreate a plot then you
might be able to simply recreate the original figure assuming the
correct interpreter functions are established. Anyway, if you are interested please take a look to see if there may be something useful. From the perspective of the IPython users out there, a question to you: is there a good way to do achieve this feature with some of the logging commands?
http://code.google.com/p/subplot/
Cheers,
Brian
-ps excuse the name of the project–I lacked creative drive at the time of naming.

···

— On Tue, 9/16/08, John Hunter <jdh2358@…287…> wrote:

From: John Hunter <jdh2358@…287…>
Subject: Re: [Matplotlib-users] save or pickle figure object
To: “Josef Koller” <jkoller@…652…>
Cc: matplotlib-users@lists.sourceforge.net
Date: Tuesday, September 16, 2008, 7:49 PM

 On Tue, Sep 16, 2008 at 5:06 PM, Josef Koller > <jkoller@...652...> wrote:
> Hi folks,
> I would like to save preliminary figures for later processing and
> refinement with matplotlib. Is there a way to save or pickle a figure
> object and later reload it. Matlab has a feature like that and and I was
> wondering if matplotlib has it too.

No, it doesn't exist. We've taken a stab at it once or twice, but
have been stymied because we make extensive use of a python extension
libray CXX, and these objects have resisted our attempts to pickle
them. With our recent transforms refactoring, which removes the
hairiest CXX dependency, it may be worth taking another look, but
noone is currently working on it.

JDH

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's
challenge
 Build the coolest Linux based applications with Moblin SDK & win
great
prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users