Skip to content

Instantly share code, notes, and snippets.

@taddeimania
Created July 21, 2015 14:55
Show Gist options
  • Save taddeimania/5cdd4ac24aff26feffa9 to your computer and use it in GitHub Desktop.
Save taddeimania/5cdd4ac24aff26feffa9 to your computer and use it in GitHub Desktop.
Graph to HttpResponse - django
from django.http import HttpResponse
import matplotlib.pyplot as plt
import io
def graph_view(request):
plt.scatter([1, 2, 3, 4], [6, 10, 12, 1])
image_file = io.BytesIO()
plt.savefig(image_file, format="png")
image_file.seek(0)
return HttpResponse(image_file, content_type="image/png")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment