Skip to content

unable to pickle.load an AxesSubplot object #3986

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sektoid0 opened this issue Jan 9, 2015 · 7 comments
Closed

unable to pickle.load an AxesSubplot object #3986

sektoid0 opened this issue Jan 9, 2015 · 7 comments

Comments

@sektoid0
Copy link

sektoid0 commented Jan 9, 2015

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'
@pelson
Copy link
Member

pelson commented Jan 9, 2015

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

@sektoid0
Copy link
Author

sektoid0 commented Jan 9, 2015

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

@blink1073
Copy link
Member

We can pickle that

@efiring
Copy link
Member

efiring commented Feb 4, 2015

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.

@prhbrt
Copy link

prhbrt commented Jan 8, 2020

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.

@QuLogic
Copy link
Member

QuLogic commented Jan 8, 2020

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.

@prhbrt
Copy link

prhbrt commented Jan 9, 2020

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants