I am testing several cases of Django and matplotlib such as this question or in french.
Each time, it works on my mac, but does not on my server, where I receive the
At the moment, matplotlib's writing functions require the seek ducktype to use the response at a file. You can write to a buffer, like this:
import io
def mplimage(request):
f = matplotlib.figure.Figure()
# Code that sets up figure goes here; in the question, that's ...
FigureCanvasAgg(f)
buf = io.BytesIO()
plt.savefig(buf, format='png')
plt.close(f)
response = HttpResponse(buf.getvalue(), content_type='image/png')
return response