Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1f07cb8

Browse files
committed
Merge pull request #1988 from pelson/pickle_bars
Added bar plot pickle support.
2 parents f4d3a1b + 695e8b5 commit 1f07cb8

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

lib/matplotlib/container.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ def remove(self):
3232
if self._remove_method:
3333
self._remove_method(self)
3434

35+
def __getstate__(self):
36+
d = self.__dict__.copy()
37+
# remove the unpicklable remove method, this will get re-added on load
38+
# (by the axes) if the artist lives on an axes.
39+
d['_remove_method'] = None
40+
return d
41+
3542
def get_label(self):
3643
"""
3744
Get the label used for this artist in the legend.

lib/matplotlib/tests/test_pickle.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ def test_simple():
114114
# ax = plt.subplot(121, projection='hammer')
115115
# recursive_pickle(ax, 'figure')
116116
# pickle.dump(ax, BytesIO(), pickle.HIGHEST_PROTOCOL)
117+
118+
plt.figure()
119+
plt.bar(left=range(10), height=range(10))
120+
pickle.dump(plt.gca(), BytesIO(), pickle.HIGHEST_PROTOCOL)
117121

118122
fig = plt.figure()
119123
ax = plt.axes()

0 commit comments

Comments
 (0)