拾取/取消拾取并显示Matplotlib图形



我在Python 3.7和Matplotlib 3.1.3中也遇到了酸洗、取消拾取和显示Matplotlab图形的问题。

我将我的数字保存为(简化代码(:

fig, ax = plt.subplots()
fig.show() #works fine
list_figs.append(fig)
output = {
"figures": list_figs
}
with open( f"mPair.pkl", "wb" ) as f:
pickle.dump( output, f )
res = pickle.load( open( f"mPair.pkl", "rb" ) )
res["figures"][0].show() #does not work

如果我直接显示该图,代码运行良好,但在酸洗/解锁后,我得到:

Traceback (most recent call last):
File "/Users/xx/opt/anaconda3/envs/nengo3/lib/python3.7/site-packages/IPython/core/interactiveshell.py", line 3331, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-3-4759ba430504>", line 1, in <module>
res1[ "fig_post" ].show()
File "/Users/xx/opt/anaconda3/envs/nengo3/lib/python3.7/site-packages/matplotlib/figure.py", line 438, in show
"created by pyplot.figure()." % err)
AttributeError: 'NoneType' object has no attribute 'manager'
Figure.show works only for figures managed by pyplot, normally created by pyplot.figure()

如果您不显示图形并在显示之前保存到pickle会发生什么,即如果您运行以下命令:

fig, ax = plt.subplots()
#fig.show() #works fine
list_figs.append(fig)
output = {
"figures": list_figs
}
with open( f"mPair.pkl", "wb" ) as f:
pickle.dump( output, f )
res = pickle.load( open( f"mPair.pkl", "rb" ) )
res["figures"][0].show() #does it work?

最新更新