Revisions
-
liuyxpp revised this gist
Sep 29, 2011 . 2 changed files with 10 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,10 @@ from flask import Flask, make_response, render_template app = Flask(__name__) @app.route("/") def index(): render_template("index.html") @app.route("/simple.png") def simple(): import datetime This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,5 @@ {% extends "layout.html" %} {% block body %} <h1>Render a Image Directly by matplotlib</h1> <img src="{{ url_for('simple') }}" alt="loading..." /> {% endblock %} -
wilsaj revised this gist
Mar 9, 2011 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ from flask import Flask, make_response app = Flask(__name__) @app.route("/simple.png") def simple(): import datetime import StringIO -
wilsaj created this gist
Mar 9, 2011 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,36 @@ from flask import Flask, make_response app = Flask(__name__) @app.route("/test.png") def simple(): import datetime import StringIO import random from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas from matplotlib.figure import Figure from matplotlib.dates import DateFormatter fig=Figure() ax=fig.add_subplot(111) x=[] y=[] now=datetime.datetime.now() delta=datetime.timedelta(days=1) for i in range(10): x.append(now) now+=delta y.append(random.randint(0, 1000)) ax.plot_date(x, y, '-') ax.xaxis.set_major_formatter(DateFormatter('%Y-%m-%d')) fig.autofmt_xdate() canvas=FigureCanvas(fig) png_output = StringIO.StringIO() canvas.print_png(png_output) response=make_response(png_output.getvalue()) response.headers['Content-Type'] = 'image/png' return response if __name__ == "__main__": app.run()