Django-dataplot Code
Status: Alpha
Brought to you by:
tdhock
File | Date | Author | Commit |
---|---|---|---|
R | 2009-05-19 | tdhock | [r181] try to add lattice version of thereAndBackPlot ... |
matplotlib | 2008-04-28 | tdhock | [r122] delete pyc file |
templates | 2009-05-25 | tdhock | [r190] new image conversion backend working |
README.txt | 2009-05-05 | tdhock | [r172] bike app now works with new django version |
__init__.py | 2007-08-05 | tdhock | [r1] import version 0.3 |
bikelog.txt | 2007-10-18 | tdhock | [r10] updated bike dataset and docs |
models.py | 2009-05-25 | tdhock | [r193] working for rpy windows installation |
urls.py | 2007-11-29 | tdhock | [r27] contrib erased from all files except VERSION |
views.py | 2007-08-05 | tdhock | [r1] import version 0.3 |
Once you've finished reading the tutorial, you know how to use the Django-dataplot API to make plot files. The next step is to make these plots dynamically generated by passing them input data from your database using Django models. Here is an example from the bike app (dataplot/bike/models.py) that is bundled with dataplot. from dataplot import R class RideManager(models.Manager): def __init__(self): self.odoplot=R.TimeSeries( 'allrides', # base plot name after MEDIA_ROOT self.get_odoplot_args, # callable that returns args for R ) def get_odoplot_args(self): qs=self.all() return { 'd':[ride.date.strftime("%s") for ride in qs], 'y':[ride.distance for ride in qs], 'transform':'cumulative', } In this example, RideManager is instantiated (dataplot/bike/models.py) as Ride.objects. From the URLconf (dataplot/bike/urls.py), we see that Ride.objects.odoplot is mapped to the context variable "plot". Finally, from the template (dataplot/bike/templates/bike/ridelist.html), we see that the template code {{plot.to_html}} is all that is needed to render the plot. If you want to see some examples of dataplot in action, you can give the bike app a test drive. This needs some more setup: - Add 'dataplot.bike' to your settings.INSTALLED_APPS. - Add the following line to your URLconfs: (r'^bike/',include('dataplot.bike.urls')), - Create the data tables with $ python manage.py syncdb Now try vising that bike/ URL you specified in your URLconf. You should be able to see a time series plot and 2 scatterplots. Inspecting the other plots in bike/models.py should reveal some strategies for making your own plots.