With matplotlibyou can do:
import StringIO
import base64
@devices_blueprint.route('/devices/test/')
def test():
img = StringIO.StringIO()
y = [1,2,3,4,5]
x = [0,2,1,3,4]
plt.plot(x,y)
plt.savefig(img, format='png')
plt.close()
img.seek(0)
plot_url = base64.b64encode(img.getvalue())
return render_template('test.html', plot_url=plot_url)
In your html put:
<img src="data:image/png;base64, {{ plot_url }}">
If you want to use seaborn , you just need to import seabornset import seabornstyles, for example
...
import seaborn as sns
...
@devices_blueprint.route('/devices/test/')
def test():
img = StringIO.StringIO()
sns.set_style("dark")
y = [1,2,3,4,5]
x = [0,2,1,3,4]
plt.plot(x,y)
plt.savefig(img, format='png')
plt.close()
img.seek(0)
plot_url = base64.b64encode(img.getvalue())
return render_template('test.html', plot_url=plot_url)
source
share