title: How to use Matplotlib in Django?
body: <p>From some examples from the Internet I made the test code below. It works! </p>
  
  <p>... BUT if I reload the page, the pie will draw itself with the same image. Some parts get darker every time I reload the page. When I restart the the development server, it is reset. How do I draw properly with <a href="http://en.wikipedia.org/wiki/Matplotlib" rel="noreferrer">Matplotlib</a> in Django? It looks like it remembers some drawings...</p>
  
  <p>Source views.py (let urls.py link to it):</p>
  
  <pre><code>from pylab import figure, axes, pie, title
  from matplotlib.backends.backend_agg import FigureCanvasAgg
  
  def test_matplotlib(request):
      f = figure(1, figsize=(6,6))
      ax = 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)
      pie(fracs, explode=explode, labels=labels, autopct='%1.1f%%', shadow=True)
      title('Raining Hogs and Dogs', bbox={'facecolor':'0.8', 'pad':5})
  
      canvas = FigureCanvasAgg(f)    
      response = HttpResponse(content_type='image/png')
      canvas.print_png(response)
      return response
  </code></pre>
  
  <p>I am using Django 1.0.1 and Python 2.6.2 (Linux).</p>