Skip to content

loading pickled figure gives: AttributeError: 'CallbackRegistry' object has no attribute 'callbacks' #8409

Closed
@capybaralet

Description

@capybaralet

Bug report

Following the accepted answer here, I'm unable to load the pickled plot.
I am doing this inside an ipython shell.

Actual outcome

# creating the file (session 1)
import matplotlib.pyplot as plt
import numpy as np
import pickle

ax = plt.subplot(111)
x = np.linspace(0, 10)
y = np.exp(x)
plt.plot(x, y)
pickle.dump(ax, file('myplot.pickle', 'w'))

Followed by

# attempting to load the file (session 2)
import matplotlib.pyplot as plt
import pickle

ax = pickle.load(file('myplot.pickle'))
plt.show()

Results in:

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

/Tmp/lisa/os_v5/anaconda/lib/python2.7/pickle.pyc in load(file)
   1382 
   1383 def load(file):
-> 1384     return Unpickler(file).load()
   1385 
   1386 def loads(str):

/Tmp/lisa/os_v5/anaconda/lib/python2.7/pickle.pyc in load(self)
    862             while 1:
    863                 key = read(1)
--> 864                 dispatch[key](self)
    865         except _Stop, stopinst:
    866             return stopinst.value

/Tmp/lisa/os_v5/anaconda/lib/python2.7/pickle.pyc in load_build(self)
   1221         setstate = getattr(inst, "__setstate__", None)
   1222         if setstate:
-> 1223             setstate(state)
   1224             return
   1225         slotstate = None

/Tmp/lisa/os_v5/anaconda/lib/python2.7/site-packages/matplotlib/figure.pyc in __setstate__(self, state)
   1443             allnums = plt.get_fignums()
   1444             num = max(allnums) + 1 if allnums else 1
-> 1445             mgr = plt._backend_mod.new_figure_manager_given_figure(num, self)
   1446 
   1447             # XXX The following is a copy and paste from pyplot. Consider

/Tmp/lisa/os_v5/anaconda/lib/python2.7/site-packages/matplotlib/backends/backend_qt5agg.pyc in new_figure_manager_given_figure(num, figure)
     49     Create a new figure manager instance for the given figure.
     50     """
---> 51     canvas = FigureCanvasQTAgg(figure)
     52     return FigureManagerQT(canvas, num)
     53 

/Tmp/lisa/os_v5/anaconda/lib/python2.7/site-packages/matplotlib/backends/backend_qt5agg.pyc in __init__(self, figure)
    247         if not hasattr(self.figure, '_original_dpi'):
    248             self.figure._original_dpi = self.figure.dpi
--> 249         self.figure.dpi = self._dpi_ratio * self.figure._original_dpi
    250         self.setAttribute(QtCore.Qt.WA_OpaquePaintEvent)
    251 

/Tmp/lisa/os_v5/anaconda/lib/python2.7/site-packages/matplotlib/figure.pyc in _set_dpi(self, dpi)
    414         self._dpi = dpi
    415         self.dpi_scale_trans.clear().scale(dpi, dpi)
--> 416         self.callbacks.process('dpi_changed', self)
    417     dpi = property(_get_dpi, _set_dpi)
    418 

/Tmp/lisa/os_v5/anaconda/lib/python2.7/site-packages/matplotlib/cbook.pyc in process(self, s, *args, **kwargs)
    544         callbacks on *s* will be called with *\*args* and *\*\*kwargs*
    545         """
--> 546         if s in self.callbacks:
    547             for cid, proxy in list(six.iteritems(self.callbacks[s])):
    548                 try:

AttributeError: 'CallbackRegistry' object has no attribute 'callbacks'

Matplotlib version

  • Matplotlib version, Python version and Platform (Windows, OSX, Linux ...)

In [29]: matplotlib.version
Out[29]: '2.0.0'

$ python -V
Python 2.7.13 :: Anaconda custom (64-bit)
$ ipython -V
5.3.0
$ uname -r
3.16.0-4-amd64

  • How did you install Matplotlib and Python (pip, anaconda, from source ...)
    I didn't install it, myself, it's the lab stack. It looks like anaconda.

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