Skip to content

Can't pickle bar plots: Failed to pickle attribute "gridline" #1719

@mspacek

Description

@mspacek

I know pickling of figures (awesome!) is still experimental, but it seems bar plots have problems. recursive_pickle() seems to give a more detailed traceback than pickle.dump():

from matplotlib.tests.test_pickle import recursive_pickle
from pylab import figure, bar
fig = figure()
bar(left=range(10), height=range(10))
recursive_pickle(fig)

gives:

Line2D((0,0),(0,1))
Failed to pickle attribute "gridline" in (list/tuple item #0 in (attribute "majorTicks" in
(attribute "xaxis" in (list/tuple item #1 in (list/tuple item #1 in (list/tuple item #0 in
(attribute "_elements" in (attribute "_axstack" in (top level object))))))))).
 Type: <class 'matplotlib.lines.Line2D'>. Traceback follows:
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-9-b0c9db9f3303> in <module>()
----> 1 recursive_pickle(fig)

/home/mspacek/src/matplotlib/lib/matplotlib/tests/test_pickle.pyc in recursive_pickle(top_obj)
     88 #        print('trying %s' % location)
     89         try:
---> 90             pickle.dump(obj, BytesIO(), pickle.HIGHEST_PROTOCOL)
     91         except Exception, err:
     92             print(obj)

TypeError: expected string or Unicode object, NoneType found

Using pickle.dump() instead like this:

import pickle
from io import BytesIO
from pylab import figure, bar
fig = figure()
bar(left=range(10), height=range(10))
pickle.dump(fig, BytesIO(), pickle.HIGHEST_PROTOCOL)

gives a different error:

PicklingError: Can't pickle <built-in method copy_from_bbox of tuple object at 0x3406a70>:
it's not found as __main__.copy_from_bbox

This is in master on Python 2.7 on Ubuntu 12.10.

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions