1

I am trying to dump a figure object into a pickle file and it keeps failing using Python 3.7.1.

#python.version = 3.7.3
#pickle.format_version = '4.0'
#dill.__version__ = '0.2.9'
print(ax, type(ax))
print(matplotlib.get_backend())
print(matplotlib.__version__)
print(sys.version_info)
with open("MyFile", "wb") as dill_file:
    dill.dump(ax, dill_file)
pt.savefig("MyFile_"+now)

The results are:

AxesSubplot(0.125,0.11;0.775x0.35) 
<class'matplotlib.axes._subplots.AxesSubplot'>
Qt5Agg
3.0.2
sys.version_info(major=3, minor=7, micro=1, releaselevel='final', serial=0)

Then the error:

> error from callback : can't pickle FigureCanvasQTAgg objects

The above code is not in a class. I have tried other backends (Agg, TkAgg, etc) with same result. I have also tried using just pickle.dump with same results.

laserpython
  • 300
  • 1
  • 6
  • 21

1 Answers1

0

You should be able to do this, according to Saving interactive Matplotlib figures

... but this is exprimental and has downsides. Consider saving to .SVG file as that answer says.

theamk
  • 1,420
  • 7
  • 14