Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. import matplotlib
  2. matplotlib.use('Agg')
  3.  
  4. from matplotlib import pyplot
  5. import numpy
  6.  
  7. from flask import Flask, send_file
  8. from cStringIO import StringIO
  9.  
  10. app = Flask(__name__)
  11.  
  12.  
  13. def plot(image):
  14. x = numpy.linspace(0, 10)
  15. y = numpy.sin(x)
  16. pyplot.plot(x, y)
  17. pyplot.savefig(image, format='png')
  18.  
  19.  
  20. @app.route('/image.png')
  21. def image_png():
  22. image = StringIO()
  23. plot(image)
  24. image.seek(0)
  25. return send_file(image,
  26. attachment_filename="image.png",
  27. as_attachment=True)
  28.  
  29.  
  30. @app.route('/')
  31. def index():
  32. return '<img src="image.png">'
  33.  
  34.  
  35. app.run(debug=True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement