X Tutup
Skip to content

When using Agg driver, pickling fails with TypeError after writing figure to PDF #6181

@gerritholl

Description

@gerritholl

When using the Agg driver, pickling fails with TypeError: cannot serialize '_io.BufferedWriter' object when printing a figure to PDF beforehand, such as illustrated below. I'm using Matplotlib 1.5.1 on Python 3.5.0. I installed Matlotlib through pip+virtualenv.

The failure is as follows:

In [1]: import matplotlib

In [2]: matplotlib.use("Agg")

In [3]: import matplotlib.pyplot

In [4]: (f, a) = matplotlib.pyplot.subplots()

In [5]: import pickle

In [6]: pickle.dump(f, open("/tmp/test1.pkl", "wb"))

In [7]: f.canvas.print_figure("/tmp/test.pdf")

In [8]: pickle.dump(f, open("/tmp/test2.pkl", "wb"))
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-8-368ac3899228> in <module>()
----> 1 pickle.dump(f, open("/tmp/test2.pkl", "wb"))

TypeError: cannot serialize '_io.BufferedWriter' object

In [9]: print(matplotlib.__version__)
1.5.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Difficulty: Mediumhttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issues

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      X Tutup