Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
import flask
app = flask.Flask(__name__)
def index():
return 'ahoj <img src="/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])
import io
buf = io.BytesIO()
plt.savefig(buf, format='png')
return flask.send_file(buf, mimetype='image/png')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment