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

Skip to content

Commit f1e43ed

Browse files
committed
Fixed post draw pickling of Line2D
1 parent ba6e42a commit f1e43ed

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

lib/matplotlib/lines.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,12 @@ def __init__(self, xdata, ydata,
352352
self._invalidy = True
353353
self.set_data(xdata, ydata)
354354

355+
def __getstate__(self):
356+
state = super(Line2D, self).__getstate__()
357+
# _linefunc will be restored on draw time.
358+
state.pop('_lineFunc', None)
359+
return state
360+
355361
def contains(self, mouseevent):
356362
"""
357363
Test whether the mouse event occurred on the line. The pick

lib/matplotlib/tests/test_pickle.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,19 @@ def test_image():
223223
pickle.dump(fig, BytesIO())
224224

225225

226+
def test_grid():
227+
from matplotlib.backends.backend_agg import new_figure_manager
228+
manager = new_figure_manager(1000)
229+
fig = manager.canvas.figure
230+
ax = fig.add_subplot(1, 1, 1)
231+
ax.grid()
232+
# Drawing the grid triggers instance methods to be attached
233+
# to the Line2D object (_lineFunc).
234+
manager.canvas.draw()
235+
236+
pickle.dump(ax, BytesIO())
237+
238+
226239
if __name__ == '__main__':
227240
import nose
228241
nose.runmodule(argv=['-s'])

0 commit comments

Comments
 (0)