I am using matplotlib to render some figure in a web app. I\'ve used fig.savefig()
before when I\'m just running scripts. However, I need a function to return a
from flask import Flask, send_file
from io import StringIO
import matplotlib.pyplot as plt
from StringIO import StringIO
@app.route('/fig/')
def fig():
plt.plot([1,2,3,4], [1,2,3,4])
img = StringIO()
plt.savefig(img)
img.seek(0)
return send_file(img, mimetype='image/png')
The other answers are correct ,I just wanted to show the header files that has to be included. This program creates a simple graph and sends it over to the html page.