title: Store multiple matplotlib figures in a dictionary and use keys to display them / modify them at will?
body: <p>I have a function that generates a plot from data I have read in. The goal is to be able to open multiple plot windows, each with a unique name, and then allow other functions to alter them at will (updating the data in them, changing colors, etc.), or to re-open plots that have been closed.</p>
  
  <p>What I have tried to do is this:</p>
  
  <p>1) Define a class, workspace, that has an attribute Figures that is a dictionary. I intend to assign my figures to unique keys in this dictionary.</p>
  
  <p>2) Now, I generate a figure, and then save it into the WS.Figures dictionary.</p>
  
  <p>3) Simplest use case, the user closes the figure and wants to re-open it, without having to go through make_plot() again. (My actual function has far, far, more complexity in the plotting - it's a pain to re-create each time manually). So I tried to write the following, which does absolutely nothing, apparently.</p>
  
  <pre><code>class WorkSpace(object):
  
      def __init__(self):
  
          self.Figures = {}
  
          return  
  
  WS = WorkSpace()
  
  def make_plot(x_data,y_data,name):
  
      plt.ion()
  
      fig = plt.figure()
  
      ax = fig.add_subplot(111)
  
      ax.plot(x_data,y_data)
  
      fig.canvas.draw()   
  
      WS.Figures[name] = fig
  
      return  
  
  def replot(name):
  
      WS.Figures[name].canvas.draw()
  
              return
  </code></pre>
  
  <p>My thinking here was that WS.Figures[name] would hold an identical copy of fig from make_plot() and so I'd just need to issue the same command to make it appear.</p>
  
  <p>I was hoping this would be the absolute easiest thing to do, and that I could then use that dictionary key to refer to the plot, update axes, etc. whenever I needed. But if I can't even replot it...</p>