title: How to save matplotlib figure as pickle file after calling show?
body: <p>I am trying to save figures created with matplotlib as pickle (not sure if other file formats would work) file so that I can reopen the figure and do further modification as needed. However, I would like to see the plot before saving. I found similar queries like:
  1. <a href="https://stackoverflow.com/questions/51264460/save-python-matplotlib-figure-as-pickle">Save python matplotlib figure as pickle</a>,
  2. <a href="https://stackoverflow.com/questions/9622163/save-plot-to-image-file-instead-of-displaying-it-using-matplotlib">Save plot to image file instead of displaying it using Matplotlib</a>,
  3. <a href="https://stackoverflow.com/questions/45310481/python-matplotlib-save-graph-as-data-file">python matplotlib save graph as data file</a>,
  4. <a href="https://stackoverflow.com/questions/4348733/saving-interactive-matplotlib-figures?rq=1">Saving interactive Matplotlib figures</a>.</p>
  
  <p>But, none of them calling show() before saving or talks about that.</p>
  
  <p>Here is the code:</p>
  
  <pre><code>import matplotlib.pyplot as plt
  import pickle
  
  fig, ax =  plt.subplots()
  ax.plot(list(range(1, 100, 10)), 'bo-')
  plt.show() # enabling this does not save anything with pickle
  
  # save the mpl figure as pickle format
  with open('fig1.pkl', 'wb') as fs:
      pickle.dump(ax, fs)
  plt.close("all")
  
  # load the saved figure as mpl figure
  with open('fig1.pkl', 'rb') as fl:
      fig1 = pickle.load(fl)
  
  plt.show()
  </code></pre>
  
  <p>It works just fine if I do not call show() in the first case. But saving seems not working with pickle if I do call. Saving with other formats (.png/.pdf) works fine. Any indication if I am doing any mistakes will be much appreciated.</p>