I am working through this example https://www.kite.com/python/answers/how-to-plot-a-bar-chart-using-a-dictionary-in-matplotlib-in-python
I am just not sure how to use flask or matplot lib to return as a web page or as an image
@app.route('/visualize')
def visualize():
a_dictionary = {"a": 1, "b": 2, "c": 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')
I am trying to embed the result like this into a html page
<img src="{{ url_for('visualize') }}" alt="Result" style="width:100%">
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.
Can anyone help please?