我使用pickle
来转储matplotlib
图,如an answer in SO所示。下面是代码片段-
import pickle
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.plot([1,2,3],[10,-10,30])
pickle.dump(fig, open('fig.pickle', 'wb'))
下面是加载pickled图的代码段-
^{pr2}$以上代码显示以下错误-
AttributeError: 'NoneType' object has no attribute 'manager'
Figure.show works only for figures managed by pyplot, normally created by pyplot.figure().
我在Ubuntu14.04LTS64位操作系统上使用Python3.6.3。下面是我的环境的更多细节-
> import matplotlib
> matplotlib.__version__
'2.1.0'
> matplotlib.get_backend()
'Qt5Agg'
> import sys
> sys.version_info
sys.version_info(major=3, minor=6, micro=3, releaselevel='final', serial=0)
我的问题似乎与this question asked at SO相似。但是,它是不同的,因为提供的答案不是运行并抛出异常。
你需要一个画布管理员才能显示你的身材。问题Matplotlib: how to show a figure that has been closed中的相同概念也适用,您可以创建一个函数来创建一个虚拟图形并窃取其管理器,如下所示(归功于上面给出答案的Jean-Sébastien)。在
使用此功能,您可以运行:
^{pr2}$相关问题 更多 >
编程相关推荐