Afficher une courbe matplotlib servie par bottle #
import matplotlib.pyplot as plt
import bottle
import math
from io import BytesIO
@bottle.route("/")
def index() :
x = [0.01 * _ for _ in range(614)]
y = [math.sin(_) for _ in x]
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(x, y)
imgdata = BytesIO()
fig.savefig(imgdata, format='png')
imgdata.seek(0)
bottle.response.set_header('Content-type', 'image/png')
return imgdata.read()
bottle.run(bottle.app(), host='0.0.0.0', port=8080, debug= True, reloader=True)