Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import flask
app = flask.Flask(__name__)
@app.route('/')
def index():
return 'ahoj <img src="/graf">'
@app.route('/graf')
def graf():
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.lines as lines
fig = plt.figure()
# nejaky matplotlib example
l1 = lines.Line2D([0, 1], [0, 1], transform=fig.transFigure, figure=fig)
l2 = lines.Line2D([0, 1], [1, 0], transform=fig.transFigure, figure=fig)
fig.lines.extend([l1, l2])
#plt.show()
import io
buf = io.BytesIO()
plt.savefig(buf, format='png')
buf.seek(0)
return flask.send_file(buf, mimetype='image/png')
app.run(debug=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment