title: Plot a graph in the html file using Django
body: <p>I am doing a monitoring system using Django. In my views file, I have defined one class called showImage which collects the information necessary to plot a graph using matplotlib.</p>
  
  <p>At the beginning, I just stored the image in a string buffer to represent it with HttpResponse:</p>
  
  <pre><code>buffer = StringIO.StringIO()
  canvas = pylab.get_current_fig_manager().canvas
  canvas.draw()
  pilImage = PIL.Image.fromstring("RGB", canvas.get_width_height(), canvas.tostring_rgb())
  pilImage.save(buffer, "PNG")
  
  # Send buffer in a http response the the browser with the mime type image/png set
  return HttpResponse(buffer.getvalue(), mimetype="image/png")
  </code></pre>
  
  <p>However, I need to implement some javaScript in the html file to add more applications. For that reason, I have decided to save the image in a variable and plot it in the html file:</p>
  
  <pre><code># serialize to HTTP response
  response = HttpResponse(buffer.getvalue(), mimetype="image/png")   
  return render_to_response('eQL/dev/showImage.html', {'response':response})
  </code></pre>
  
  <p>My question is that I don't really know how to represent it in the html file because I didn't find any example doing it. Any one knows the answer?</p>
  
  <p>Thanks in advance!</p>