<p dir="auto">Trying to save an unpickled figure using <code class="notranslate">savefig</code> throws an<br>
<code class="notranslate">AttributeError: 'CallbackRegistry' object has no attribute 'callbacks' </code></p>
<p dir="auto">The issue is reproduced using the following code in python 2.7 (from WinPython2.7.10), Windows 8.1 (64bit), matplotlib 2.0.0</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="import matplotlib.pyplot as plt
import pickle

fig= plt.figure()
ax = fig.add_subplot(111)
ax.plot([9,8,7])

pickle.dump(fig, file('fig.pickle', 'w'))

plt.close(&quot;all&quot;)

fig_pickled1 = pickle.load(file('fig.pickle'))

plt.savefig(__file__+&quot;.png&quot;)
"><pre class="notranslate"><code class="notranslate">import matplotlib.pyplot as plt
import pickle

fig= plt.figure()
ax = fig.add_subplot(111)
ax.plot([9,8,7])

pickle.dump(fig, file('fig.pickle', 'w'))

plt.close("all")

fig_pickled1 = pickle.load(file('fig.pickle'))

plt.savefig(__file__+".png")

</code></pre></div>
<p dir="auto">The traceback of the call to this is</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Traceback (most recent call last):
  File &quot;D:\Data\Computer\Entwicklung\python\test\SO_pickle_matplotlib.py&quot;, line 43, in &lt;module&gt;
    plt.savefig(__file__+&quot;.png&quot;)
  File &quot;C:\WinPython\WinPython-64bit-2.7.10.3\python-2.7.10.amd64\lib\site-packages\matplotlib\pyplot.py&quot;, line 697, in savefig
    res = fig.savefig(*args, **kwargs)
  File &quot;C:\WinPython\WinPython-64bit-2.7.10.3\python-2.7.10.amd64\lib\site-packages\matplotlib\figure.py&quot;, line 1572, in savefig
    self.canvas.print_figure(*args, **kwargs)
  File &quot;C:\WinPython\WinPython-64bit-2.7.10.3\python-2.7.10.amd64\lib\site-packages\matplotlib\backends\backend_qt5agg.py&quot;, line 222, in print_figure
    FigureCanvasAgg.print_figure(self, *args, **kwargs)
  File &quot;C:\WinPython\WinPython-64bit-2.7.10.3\python-2.7.10.amd64\lib\site-packages\matplotlib\backend_bases.py&quot;, line 2163, in print_figure
    self.figure.dpi = dpi
  File &quot;C:\WinPython\WinPython-64bit-2.7.10.3\python-2.7.10.amd64\lib\site-packages\matplotlib\figure.py&quot;, line 416, in _set_dpi
    self.callbacks.process('dpi_changed', self)
  File &quot;C:\WinPython\WinPython-64bit-2.7.10.3\python-2.7.10.amd64\lib\site-packages\matplotlib\cbook.py&quot;, line 546, in process
    if s in self.callbacks:
AttributeError: 'CallbackRegistry' object has no attribute 'callbacks'
"><pre class="notranslate"><code class="notranslate">Traceback (most recent call last):
  File "D:\Data\Computer\Entwicklung\python\test\SO_pickle_matplotlib.py", line 43, in &lt;module&gt;
    plt.savefig(__file__+".png")
  File "C:\WinPython\WinPython-64bit-2.7.10.3\python-2.7.10.amd64\lib\site-packages\matplotlib\pyplot.py", line 697, in savefig
    res = fig.savefig(*args, **kwargs)
  File "C:\WinPython\WinPython-64bit-2.7.10.3\python-2.7.10.amd64\lib\site-packages\matplotlib\figure.py", line 1572, in savefig
    self.canvas.print_figure(*args, **kwargs)
  File "C:\WinPython\WinPython-64bit-2.7.10.3\python-2.7.10.amd64\lib\site-packages\matplotlib\backends\backend_qt5agg.py", line 222, in print_figure
    FigureCanvasAgg.print_figure(self, *args, **kwargs)
  File "C:\WinPython\WinPython-64bit-2.7.10.3\python-2.7.10.amd64\lib\site-packages\matplotlib\backend_bases.py", line 2163, in print_figure
    self.figure.dpi = dpi
  File "C:\WinPython\WinPython-64bit-2.7.10.3\python-2.7.10.amd64\lib\site-packages\matplotlib\figure.py", line 416, in _set_dpi
    self.callbacks.process('dpi_changed', self)
  File "C:\WinPython\WinPython-64bit-2.7.10.3\python-2.7.10.amd64\lib\site-packages\matplotlib\cbook.py", line 546, in process
    if s in self.callbacks:
AttributeError: 'CallbackRegistry' object has no attribute 'callbacks'

</code></pre></div>
<p dir="auto">Using <code class="notranslate">plt.show()</code> instead of saving works fine; the figure is shown as expected.<br>
Using <code class="notranslate">pickle.dump(fig, open('fig.pickle', 'wb'))</code> for pickling and <code class="notranslate">fig_pickled1 = pickle.load(open('fig.pickle', "rb"))</code> does not change the behaviour.<br>
Also, moving the loading to a new file has no effect.<br>
Trying to save in other formats like <code class="notranslate">pdf</code> does not change anything.</p>
<p dir="auto">Using matplotlib version 1.5.1 installed from pip on Linux (Fedora 22 and CentOS 7).</p>
<p dir="auto">Trying to set certain attributes (e.g. cmap, clim) on a PatchCollection loaded from a pickle leads to an <code class="notranslate">AttributeError: 'CallbackRegistry' object has no attribute 'callbacks'</code>:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="Traceback (most recent call last):
  File &quot;mpl_pickle_pc_test.py&quot;, line 48, in &lt;module&gt;
    pc_loaded.set_cmap(cmap)
  File &quot;&lt;venv&gt;/lib/python2.7/site-packages/matplotlib/cm.py&quot;, line 308, in set_cmap
    self.changed()
  File &quot;&lt;venv&gt;/lib/python2.7/site-packages/matplotlib/cm.py&quot;, line 359, in changed
    self.callbacksSM.process('changed', self)
  File &quot;&lt;venv&gt;/lib/python2.7/site-packages/matplotlib/cbook.py&quot;, line 560, in process
    if s in self.callbacks:
AttributeError: 'CallbackRegistry' object has no attribute 'callbacks'"><pre class="notranslate"><span class="pl-v">Traceback</span> (<span class="pl-s1">most</span> <span class="pl-s1">recent</span> <span class="pl-s1">call</span> <span class="pl-s1">last</span>):
  <span class="pl-v">File</span> <span class="pl-s">"mpl_pickle_pc_test.py"</span>, <span class="pl-s1">line</span> <span class="pl-c1">48</span>, <span class="pl-s1">in</span> <span class="pl-c1">&lt;</span><span class="pl-s1">module</span><span class="pl-c1">&gt;</span>
    <span class="pl-s1">pc_loaded</span>.<span class="pl-en">set_cmap</span>(<span class="pl-s1">cmap</span>)
  <span class="pl-v">File</span> <span class="pl-s">"&lt;venv&gt;/lib/python2.7/site-packages/matplotlib/cm.py"</span>, <span class="pl-s1">line</span> <span class="pl-c1">308</span>, <span class="pl-s1">in</span> <span class="pl-s1">set_cmap</span>
    <span class="pl-s1">self</span>.<span class="pl-en">changed</span>()
  <span class="pl-v">File</span> <span class="pl-s">"&lt;venv&gt;/lib/python2.7/site-packages/matplotlib/cm.py"</span>, <span class="pl-s1">line</span> <span class="pl-c1">359</span>, <span class="pl-s1">in</span> <span class="pl-s1">changed</span>
    <span class="pl-s1">self</span>.<span class="pl-s1">callbacksSM</span>.<span class="pl-en">process</span>(<span class="pl-s">'changed'</span>, <span class="pl-s1">self</span>)
  <span class="pl-v">File</span> <span class="pl-s">"&lt;venv&gt;/lib/python2.7/site-packages/matplotlib/cbook.py"</span>, <span class="pl-s1">line</span> <span class="pl-c1">560</span>, <span class="pl-s1">in</span> <span class="pl-s1">process</span>
    <span class="pl-k">if</span> <span class="pl-s1">s</span> <span class="pl-c1">in</span> <span class="pl-s1">self</span>.<span class="pl-s1">callbacks</span>:
<span class="pl-v">AttributeError</span>: <span class="pl-s">'CallbackRegistry'</span> <span class="pl-s1">object</span> <span class="pl-s1">has</span> <span class="pl-s1">no</span> <span class="pl-s1">attribute</span> <span class="pl-s">'callbacks'</span></pre></div>
<p dir="auto">I've created a gist to reproduce this behavior: <a href="https://gist.github.com/jasoncpatton/c19d19b638ff10ece5d2">https://gist.github.com/jasoncpatton/c19d19b638ff10ece5d2</a></p>
<p dir="auto">Oddly, if you catch the AttributeError and ignore it (set <code class="notranslate">use_try = True</code> in the gist), the attribute is actually set on the PatchCollection. However, using any methods that take the PatchCollection as a parameter (e.g. <code class="notranslate">fig.colorbar()</code>) will also break your code.</p>
<p dir="auto">This behavior does not occur in version 1.4.3.</p>