O'Reilly logo

Django 1.1 Testing and Debugging by Karen M. Tracey

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Results display using matplotlib

The matplotlib library provides another alternative for generating charts from Python. It can be found on the Python Package Index site, http://pypi.python.org/pypi/matplotlib. The version of matplotlib used in this chapter is 0.98.3.

With matplotlib, our application cannot simply construct a URL and push the task of generating and serving the image data off to another host. Instead, we need to write a view that will generate and serve the image data. After some investigation of the matplotlib APIs, an initial implementation (in survey/views.py) might be:

from django.http import HttpResponse from survey.models import Question from matplotlib.figure import Figure from matplotlib.backends.backend_agg import FigureCanvasAgg ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required