简体   繁体   English

不能腌制或莳萝FigureCanvasQTAgg

[英]Can't pickle or dill FigureCanvasQTAgg

I am trying to dump a figure object into a pickle file and it keeps failing using Python 3.7.1. 我试图将图形对象转储到pickle文件中,使用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 >回调错误:无法腌制FigureCanvasQTAgg对象

The above code is not in a class. 上面的代码不在类中。 I have tried other backends (Agg, TkAgg, etc) with same result. 我尝试了其他后端(Agg,TkAgg等),结果相同。 I have also tried using just pickle.dump with same results. 我也尝试过只用pickle.dump获得相同的结果。

You should be able to do this, according to Saving interactive Matplotlib figures 根据保存交互式Matplotlib数据 ,您应该能够做到这一点

... but this is exprimental and has downsides. ...但这是实验性的,也有缺点。 Consider saving to .SVG file as that answer says. 如该答案所述,考虑保存到.SVG文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM