Skip to content

Instantly share code, notes, and snippets.

@messa
Created June 12, 2017 17:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save messa/a0be91834971e998fbc993ede450b735 to your computer and use it in GitHub Desktop.
Save messa/a0be91834971e998fbc993ede450b735 to your computer and use it in GitHub Desktop.
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