title: How to add a plot to a Figure in matplotlib?
body: <p>i'm using matplotlib with django. I'm trying to create bar charts.</p>
  
  <p>i followed the <a href="http://www.scipy.org/Cookbook/Matplotlib/Django" rel="nofollow">cookbook</a>, but i just got a grey rectangular box.</p>
  
  <p>Now I'm using the following code, and have a title and axes.</p>
  
  <p>How can I add a bar graph to the figure? Currently there is no actual data inside the axes.</p>
  
  <p>Here's my charting code:</p>
  
  <pre><code>from matplotlib.backends.backend_agg import FigureCanvasAgg 
  from matplotlib.figure import Figure
  import matplotlib.pyplot as plt
  
  class Chart(object):
  
      ## Creates a bar chart of the given data
      @staticmethod
      def bar(data):
          figure = Figure(figsize=(6,6))
          ax = figure.add_axes([0.1, 0.1, 0.8, 0.8])
          labels = 'Frogs', 'Hogs', 'Dogs', 'Logs'
          fracs = [15, 30, 45, 10]
          explode=(0, 0.05, 0, 0)
          plt.pie(fracs, explode=explode, labels=labels, autopct='%1.1f%%', shadow=True)
          figure.suptitle('Raining Hogs and Dogs', fontsize=14)
  
          canvas = FigureCanvasAgg(figure)
  
          return canvas
  </code></pre>
  
  <p>In my view I have:</p>
  
  <pre><code>canvas = Chart.bar(results)
  
  # turn the returned canvas into an HTTP response
  response=HttpResponse(content_type='image/png')
  canvas.print_png(response)
  return response
  </code></pre>