title: Closing a figure in python
body: <p>I am making a lot of plots and saving them to a file, it all works, but during the compilation I get the following message: </p>
  
  <pre><code>RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface (`matplotlib.pyplot.figure`) are retained until explicitly closed and may consume too much memory. (To control this warning, see the rcParam `figure.max_open_warning`).
    fig = self.plt.figure(figsize=self.figsize)
  </code></pre>
  
  <p>So I think I could improve the code by closing the figures, I googled it and found that I should use <code>fig.close()</code>. However I get the following error <code>'Figure' object has no attribute 'close'</code>. How should I make it work?</p>
  
  <p>This is the loop in which I create plots:</p>
  
  <pre><code>for i in years:
      ax = newdf.plot.barh(y=str(i), rot=0) 
      fig = ax.get_figure()
      fig.savefig('C:\\Users\\rysza\\Desktop\\python data analysis\\zajecia3\\figure'+str(i)+'.jpeg',bbox_inches='tight')
      fig.close()
  </code></pre>