@@ -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
@@ -195,17 +197,47 @@ def test_complete():
195197
196198def test_no_pyplot ():
197199 # tests pickle-ability of a figure not created with pyplot
198-
199- import pickle as p
200200 from matplotlib .backends .backend_pdf import FigureCanvasPdf as fc
201201 from matplotlib .figure import Figure
202202
203203 fig = Figure ()
204- can = fc (fig )
204+ _ = fc (fig )
205205 ax = fig .add_subplot (1 , 1 , 1 )
206206 ax .plot ([1 , 2 , 3 ], [1 , 2 , 3 ])
207-
208- # Uncomment to debug any unpicklable objects. This is slow so is not
209- # uncommented by default.
210- # recursive_pickle(fig)
211207 pickle .dump (fig , BytesIO (), pickle .HIGHEST_PROTOCOL )
208+
209+
210+ def test_renderer ():
211+ from matplotlib .backends .backend_agg import RendererAgg
212+ renderer = RendererAgg (10 , 20 , 30 )
213+ pickle .dump (renderer , BytesIO ())
214+
215+
216+ def test_image ():
217+ # Prior to v1.4.0 the Image would cache data which was not picklable
218+ # once it had been drawn.
219+ from matplotlib .backends .backend_agg import new_figure_manager
220+ manager = new_figure_manager (1000 )
221+ fig = manager .canvas .figure
222+ ax = fig .add_subplot (1 , 1 , 1 )
223+ ax .imshow (np .arange (12 ).reshape (3 , 4 ))
224+ manager .canvas .draw ()
225+ pickle .dump (fig , BytesIO ())
226+
227+
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+
241+ if __name__ == '__main__' :
242+ import nose
243+ nose .runmodule (argv = ['-s' ])
0 commit comments