I am using matplotlib in a django app and would like to directly return the rendered image.
So far I can go plt.savefig(...), then return the location of the im
Employ ducktyping and pass a object of your own, in disguise of file object
class MyFile(object):
def __init__(self):
self._data = ""
def write(self, data):
self._data += data
myfile = MyFile()
fig.savefig(myfile)
print myfile._data
you can use myfile = StringIO.StringIO() instead in real code and return data in reponse e.g.
output = StringIO.StringIO()
fig.savefig(output)
contents = output.getvalue()
return HttpResponse(contents , mimetype="image/png")