Skip to content

Commit 4ba18d4

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

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

lib/matplotlib/lines.py

+6
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

+16-1
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ def test_simple():
107107
plt.plot(list(xrange(10)), label='foobar')
108108
plt.legend()
109109

110+
# Uncomment to debug any unpicklable objects. This is slow so is not
111+
# uncommented by default.
110112
# recursive_pickle(fig)
111113
pickle.dump(ax, BytesIO(), pickle.HIGHEST_PROTOCOL)
112114

@@ -217,12 +219,25 @@ def test_image():
217219
from matplotlib.backends.backend_agg import new_figure_manager
218220
manager = new_figure_manager(1000)
219221
fig = manager.canvas.figure
220-
ax = fig.add_subplot(1,1,1)
222+
ax = fig.add_subplot(1, 1, 1)
221223
ax.imshow(np.arange(12).reshape(3, 4))
222224
manager.canvas.draw()
223225
pickle.dump(fig, BytesIO())
224226

225227

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

0 commit comments

Comments
 (0)