Skip to content

unable to pickle.load an AxesSubplot object #3986

Closed

Description

@sektoid0

Python 2.7.9 :: Anaconda 2.1.0 (64-bit)
Matplotlib 1.4.0

On an example code from http://stackoverflow.com/questions/7290370/store-and-reload-matplotlib-pyplot-object getting a following exception on pickle load.

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-2-37de7fcd9451> in <module>()
      2 import pickle
      3 
----> 4 ax = pickle.load(file('myplot.pickle', 'rb'))
      5 plt.show()    

/home/anaconda/envs/py27/lib/python2.7/pickle.pyc in load(file)
   1376 
   1377 def load(file):
-> 1378     return Unpickler(file).load()
   1379 
   1380 def loads(str):    

/home/anaconda/envs/py27/lib/python2.7/pickle.pyc in load(self)
    856             while 1:
    857                 key = read(1)
--> 858                 dispatch[key](self)
    859         except _Stop, stopinst:
    860             return stopinst.value    

/home/anaconda/envs/py27/lib/python2.7/pickle.pyc in load_build(self)
   1215         setstate = getattr(inst, "__setstate__", None)
   1216         if setstate:
-> 1217             setstate(state)
   1218             return
   1219         slotstate = None    

/home/anaconda/envs/py27/lib/python2.7/site-packages/matplotlib/figure.pyc in __setstate__(self, state)
   1343             allnums = plt.get_fignums()
   1344             num = max(allnums) + 1 if allnums else 1
-> 1345             mgr = plt._backend_mod.new_figure_manager_given_figure(num, self)
   1346 
   1347             # XXX The following is a copy and paste from pyplot. Consider    

AttributeError: 'module' object has no attribute 'new_figure_manager_given_figure'

Activity

  1. pelson commented on Jan 9, 2015

    @pelson
    Member

    Are you loading a pickle file created with the same version of matplotlib? Can you provide the code to reproduce. Thanks.

  2. sektoid0 commented on Jan 9, 2015

    @sektoid0
    Author

    Yes. The same version of matplotlib. The code is exactly the one listed here:
    http://stackoverflow.com/questions/7290370/store-and-reload-matplotlib-pyplot-object

  3. blink1073 commented on Jan 22, 2015

    @blink1073
    Member
  4. efiring commented on Feb 4, 2015

    @efiring
    Member

    I can't reproduce the problem; with matplotlib 1.4.0, Anaconda 2.1.0, on OSX, if I cut and paste the code on that page as instructed, it works perfectly.

  5. prhbrt commented on Jan 8, 2020

    @prhbrt

    I solved this issue in Jupyter notebooks, not Anaconda, using

    %matplotlib agg
    
    with open('file.p3', 'rb') as f:
        model = pickle.load(f)
    
    %matplotlib inline
    

    That is, this is ipython code, not python code.

  6. QuLogic commented on Jan 8, 2020

    @QuLogic
    Member

    This bug report doesn't involve notebooks. It's also 4 years old and closed. Your workaround may be helpful to you, but it's not really relevant here.

  7. prhbrt commented on Jan 9, 2020

    @prhbrt

    Actually, the %matplotlib agg translates in to python code, so I could imagine it could be useful for someone doing plain python. Notebooks are just python in the end. I also don't think this is ipython vs. python related, I think it's related to the backend of matplotlib. So my suggestion was to temporarily switch backends.

    Moreover, the bug was closed because it couldn't be reproduced. So anyone who googles this error and gets to this page, now at least has a lead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions