My needs are to create line, bar and pie charts.
Many Thanks
Gerry
--
Gerry Steele
http://belfast.no-ip.info/
-joe
> My needs are to create line, bar and pie charts.
One fast way for line graphs would be plain PIL
(http://www.pythonware.com/products/pil/) module. But the results are
usually not really pretty: No antialiasing of lines, except you also use
the aggdraw module (http://effbot.org/zone/aggdraw-index.htm).
If you want do do really nice graphs, you might take a look at some
screenshots of matplotlib:
http://matplotlib.sourceforge.net/screenshots.html
The module is quite large, but has really many functions: from simple
pie charts (3D too) up to finance charts which gets data from
finance.yahoo.com
I took quite some time until I figured how matplotlib/pylab works, but
eventually I succeeded. Hopefully you'll get to some good results
faster than me :)
Martin
I had a similar experience with matplotlib. The docs are not always too
easy to understand so you have to do some digging and experimenting but
it is very flexible and powerful and the resulting charts are good quality.
A recipe here shows how to return a matplotlib image in a Django response:
http://www.scipy.org/Cookbook/Matplotlib/Django
Kent
If you still need help with making data-driven plots, why don't you check
out my new Django package --- I'd like some testers and comments.
Basically it is an interface to the R programming language (for statistics
and graphics) through the RPy package. You can download my latest release:
http://www.ocf.berkeley.edu/~tdhock/dataplot-0.2.tgz
I'm a statistician who has been using this system for some time at my
work, but I finally am getting around to generalizing it and packaging it
for general use with the Django framework.
The installation instructions are in INSTALL.txt in the archive.
Documentation is mostly present in docstrings at the moment -- I'm working
on more tutorials, but the .txt files and the example app should be enough
to get you started.
Sincerely,
Toby Dylan Hocking
http://www.ocf.berkeley.edu/~tdhock
I'm excited to hear that you got a copy of django.contrib.dataplot and you
are trying it out. I will try to help you debug the problem, but the
full traceback may be more useful. Can you send it?
The purpose of the get_r_fun method is to look at the current R
environment and check if the desired R function has been source'ed yet.
This is one of the first steps before passing the data before R.
I take the "r has no attribute generic" to refer to one of the generic
plotting functions named in one of the RPlot subclasses -- you must be
dealing with Scatter, TimeSeries, or NormalQQPlot, right? Are you sure it
doesn't say something like "r has no attribute generic.scatter.plot"? You
might try changing the dots . to underscores _ in the
r_fun_name='generic.scatter.plot' line in the definition of the
ScatterPlot subclass.
Maybe your version of RPy isn't translating python names into R names the
same way as mine is? I'm using RPy 0.4.6-3ubuntu2 Python 2.4.2-0ubuntu3
and R 2.2.1-2 on ubuntu dapper. What are your versions?
Sincerely,
Toby Dylan Hocking
http://www.ocf.berkeley.edu/~tdhock
> --
> Regards,
> Ben Ford
> ben.f...@gmail.com
> +628111880346
>
> >
>
Initial reaction-- sweet!
After linking dataplot into my contribs dir and adding both dataplot
and dataplot.bike in my INSTALLED_APPS, I get this:
jdunck@jdunckpeg2:~/work/pegasus/b-schools$ ~/django-admin.py syncdb
RHOME= /usr/lib/R
RVERSION= 2.4.1
RVER= 2041
RUSER= /home/jdunck
Loading Rpy version 2041 .. Done.
Creating the R object 'r' .. Done
Error: Couldn't install apps, because there were errors in one or more models:
bike.ride: "distance": FloatFields require a "decimal_places" attribute.
....
A quick check indicates that this is because of a backwards incompat in Django:
http://code.djangoproject.com/wiki/BackwardsIncompatibleChanges#RenamedFloatFieldtoDecimalField
I guess you're running on latest trunk?
I see what you're doing now. There are a couple things I should mention.
First of all, you are right: getattr(r,'generic.scatter.plot') is not the
same as typing r.generic.scatter.plot -- instead, it invokes the
__getattr__ method of r, and looks for something by that name in the R
namespace. Having found nothing, it raises an exception. If it did find
something -- you'd have to rplot.source_for_function() or
r.source("/path/to/generic.scatter.plot.R") first -- it would return the
function, and assign it to r.generic_scatter_plot (rpy automatically
translates R dots . to python underscores _ in variable names).
It also looks like our package versions are significantly different. RPy
is notoriously touchy about what particular package versions you are
using, so that may be the cause of django.contrib.dataplot's failure on
your system. But despite the differences in package versions, I bet that
if you source the R code first, you will be able to execute the getattr
properly, i.e.
>>> from rpy import r
>>> r.source("/usr/local/lib/python2.4/site-packages/django/contrib/dataplot/R/generic.scatter.plot.R")
{'visible': False, 'value': <Robj object at 0xb7e11190>}
>>> r.generic_scatter_plot
<Robj object at 0xb7e111a0>
However, the whole point of django.contrib.dataplot is that it takes care
of these details for you ---
>>> from django.contrib import dataplot
>>> plot=dataplot.Scatter('myscatterplot',fun_to_get_scatter_data)
>>> plot.to_html()
Have you tried to get the demo bike app (django.contrib.dataplot.bike) to
work? If you are able to get those simple examples working, it should be
straightforward to translate the design paradigm to your problems.
Sincerely,
Toby Dylan Hocking
http://www.ocf.berkeley.edu/~tdhock
>> http://www.ocf.berkeley.edu/~tdhock<http://www.ocf.berkeley.edu/%7Etdhock>
>>
>> On Wed, 11 Jul 2007, Ben Ford wrote:
>>
>>> Hi Toby
>>> I've grabbed a copy of your code but the RPlot.get_r_fun method isn't
>>> working for me... Could you perhaps explain how it does the mapping to
>> the R
>>> function? What my testing is saying to me is that r (the one that's
>> imported
>>> at the top of __init__.py) has no attribute generic... I've had a very
>> brief
>>> look at rpy before, but I'm not exactly familiar with it's inner
>>> workings....
>>> Great work, I've been meaning to have a crack at something like this for
>>> ages!!
>>> Ben
>>>
>>> On 11/07/07, Toby Dylan Hocking <tdh...@ocf.berkeley.edu> wrote:
>>>>
>>>>
>>>> Hi there,
>>>>
>>>> If you still need help with making data-driven plots, why don't you
>> check
>>>> out my new Django package --- I'd like some testers and comments.
>>>> Basically it is an interface to the R programming language (for
>> statistics
>>>> and graphics) through the RPy package. You can download my latest
>> release:
>>>>
>>>> http://www.ocf.berkeley.edu/~tdhock/dataplot-0.2.tgz<http://www.ocf.berkeley.edu/%7Etdhock/dataplot-0.2.tgz>
>>>>
>>>> I'm a statistician who has been using this system for some time at my
>>>> work, but I finally am getting around to generalizing it and packaging
>> it
>>>> for general use with the Django framework.
>>>>
>>>> The installation instructions are in INSTALL.txt in the archive.
>>>> Documentation is mostly present in docstrings at the moment -- I'm
>> working
>>>> on more tutorials, but the .txt files and the example app should be
>> enough
>>>> to get you started.
>>>>
>>>> Sincerely,
>>>> Toby Dylan Hocking
>>>> http://www.ocf.berkeley.edu/~tdhock<http://www.ocf.berkeley.edu/%7Etdhock>
Thanks for the input. You are correct: I am running a recent copy of
django from SVN on the primary machine I am using to develop
django.contrib.dataplot.
In fact, I ran into the same problem that you did when I tried to port
django.contrib.dataplot to a different machine -- a machine running Django
0.95. After realizing the existence of the new backwards-incompatible
changes, I was able to get the django.contrib.dataplot.bike demo app
working on my old system by simply adding the max_digits and
decimal_places arguments to the bike/models.py FloatFields. Another
solution would have been to upgrade the django libraries to the new trunk
versions.
Again, thanks for trying out my library. I'm anxious to hear if you're
able to get it working. Once you are able to get the bike app working on
your system, it should be straightforward to translate the design
paradigms to your plotting application.
Sincerely,
Toby Dylan Hocking
http://www.ocf.berkeley.edu/~tdhock
Hi Ben,
I see what you're doing now. There are a couple things I should mention.
First of all, you are right: getattr(r,'generic.scatter.plot') is not the
same as typing r.generic.scatter.plot -- instead, it invokes the
__getattr__ method of r, and looks for something by that name in the R
namespace. Having found nothing, it raises an exception. If it did find
something -- you'd have to rplot.source_for_function () or
r.source("/path/to/generic.scatter.plot.R") first -- it would return the
function, and assign it to r.generic_scatter_plot (rpy automatically
translates R dots . to python underscores _ in variable names).
It also looks like our package versions are significantly different. RPy
is notoriously touchy about what particular package versions you are
using, so that may be the cause of django.contrib.dataplot's failure on
your system. But despite the differences in package versions, I bet that
if you source the R code first, you will be able to execute the getattr
properly, i.e.
>>> from rpy import r
>>> r.source("/usr/local/lib/python2.4/site-packages/django/contrib/dataplot/R/generic.scatter.plot.R")
{'visible': False, 'value': <Robj object at 0xb7e11190>}
>>> r.generic_scatter_plot
<Robj object at 0xb7e111a0>
However, the whole point of django.contrib.dataplot is that it takes care
of these details for you ---
>>> from django.contrib import dataplot
>>> plot= dataplot.Scatter('myscatterplot',fun_to_get_scatter_data)