title: simple matplotlib as embedded image in web page generated by flask
body: <p>I am working through this example <a href="https://www.kite.com/python/answers/how-to-plot-a-bar-chart-using-a-dictionary-in-matplotlib-in-python" rel="nofollow noreferrer">https://www.kite.com/python/answers/how-to-plot-a-bar-chart-using-a-dictionary-in-matplotlib-in-python</a></p>
  <p>I am just not sure how to use flask or matplot lib to return as a web page or as an image</p>
  <pre><code>@app.route('/visualize')
  def visualize():
  
  
      a_dictionary = {&quot;a&quot;: 1, &quot;b&quot;: 2, &quot;c&quot;: 3}
      keys = a_dictionary.keys()
      values = a_dictionary.values()
      plt.bar(keys, values)
      bytes_image = io.BytesIO()
      plt.savefig('img')
  
      return send_file(img,mimetype='img')
  </code></pre>
  <p>I am trying to embed the result like this into a html  page</p>
  <pre><code>&lt;img src=&quot;{{ url_for('visualize') }}&quot; alt=&quot;Result&quot; style=&quot;width:100%&quot;&gt;
  </code></pre>
  <p>I am getting confused how to apply other works on the internet into this case. There seem to be different solutions about which modules are imported, some using seaborn.</p>
  <p>Can anyone help please?</p>