title: matplotlib embed figures in auto generated html
body: <p>I want to embed a figure generated by python matplotlib into a html file with other content. Is that possible?</p>
  
  <p>What I have thought is saving figures as png file and then use <code>&lt;img&gt;</code> tag to refer to it.</p>
  
  <p>Some code I was trying to use are like:</p>
  
  <pre><code>import matplotlib.pyplot as plt
  fig = plt.figure()
  #plot sth
  plt.savefig('test.png')
  
  html = 'Some html head' + '&lt;img src=\'test.png\'&gt;' + 'Some more html'
  
  with open('test.html','w') as f:
      f.write(html)
  </code></pre>
  
  <p>However, this will generate two files instead of one and I don't have a server to host the png file. Is that possible to embed the figure in the html? How do I do it in python.</p>
  
  <p>Thank you.</p>