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

Skip to content

Commit 895301a

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

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
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: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,12 +217,25 @@ def test_image():
217217
from matplotlib.backends.backend_agg import new_figure_manager
218218
manager = new_figure_manager(1000)
219219
fig = manager.canvas.figure
220-
ax = fig.add_subplot(1,1,1)
220+
ax = fig.add_subplot(1, 1, 1)
221221
ax.imshow(np.arange(12).reshape(3, 4))
222222
manager.canvas.draw()
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)