Store and reload matplotlib.pyplot object

后端 未结 5 963
别跟我提以往
别跟我提以往 2020-11-28 03:50

I work in an psudo-operational environment where we make new imagery on receipt of data. Sometimes when new data comes in, we need to re-open an image and update that image

5条回答
  •  自闭症患者
    2020-11-28 04:03

    I'm also having problems with this in Python 3.7 and Matplotlib 3.1.3.

    I save my figures as (simplified code):

    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
    

    The code works fine if I directly show the figure but after pickling/unpickling I get:

    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 "", line 1, in 
        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()
    

提交回复
热议问题