My tags and title quite clearly state my problem. I want to use matplotlib to create real-time plots in Google App Engine. I\'ve read the documentation and searched on SO and Go
I'm not familiar with sys module. To give an answer to the question I prefer using webapp2. This is a working handler:
import webapp2
import StringIO
import numpy as np
import matplotlib.pyplot as plt
class MainPage(webapp2.RequestHandler):
def get(self):
plt.plot(np.random.random((20)))
sio = StringIO.StringIO()
plt.savefig(sio, format="png")
img_b64 = sio.getvalue().encode("base64").strip()
plt.clf()
sio.close()
self.response.write("""""")
self.response.write("" % img_b64)
self.response.write(""" """)
app = webapp2.WSGIApplication([('/', MainPage)], debug=True)
Alternatively, you could write the sio.getvalue()
in the blobstore with files api and use the method get_serving_url()
of images api for avoid to encode in base64.