diff --git a/lib/matplotlib/container.py b/lib/matplotlib/container.py index ac6f2de2f0ec..b1754a24da75 100644 --- a/lib/matplotlib/container.py +++ b/lib/matplotlib/container.py @@ -32,6 +32,13 @@ def remove(self): if self._remove_method: self._remove_method(self) + def __getstate__(self): + d = self.__dict__.copy() + # remove the unpicklable remove method, this will get re-added on load + # (by the axes) if the artist lives on an axes. + d['_remove_method'] = None + return d + def get_label(self): """ Get the label used for this artist in the legend. diff --git a/lib/matplotlib/tests/test_pickle.py b/lib/matplotlib/tests/test_pickle.py index 0af210e112e6..a687c624d866 100644 --- a/lib/matplotlib/tests/test_pickle.py +++ b/lib/matplotlib/tests/test_pickle.py @@ -114,6 +114,10 @@ def test_simple(): # ax = plt.subplot(121, projection='hammer') # recursive_pickle(ax, 'figure') # pickle.dump(ax, BytesIO(), pickle.HIGHEST_PROTOCOL) + + plt.figure() + plt.bar(left=range(10), height=range(10)) + pickle.dump(plt.gca(), BytesIO(), pickle.HIGHEST_PROTOCOL) @image_comparison(baseline_images=['multi_pickle'],