views:

54

answers:

3

Is it a good idea to code such a script in Python and in which language is handy for fast performance and useful libraries/frameworks for charts?(charts would be created after calculating an expression which is input from the user)

EDIT:It's a web server-side script

+1  A: 

I'm not exactly sure what you mean by "charts", but if you mean plotting/creating graphs, perhaps you should look at R, a free software environment for statistical computing and graphics. It has good graphics capabilities, and can connect to many environments, including Python.

bhm
i guess i forgot to specify...it's a web application.So I have to convert the charts to images and I wonder if there isn't native php or python technic
Alexander Ivanov
A: 

It's reasonably straightforward to generate graphics on the fly in python using the reportlab library http://www.reportlab.com/software/opensource/. It includes functionality to create bar, line, pie, etc. charts from lists of data. Don't be misled by the emphasis on generating PDFs, the library also can create just PNG or GIF images. Also, the official documentation is very verbose and intimidating, but it's quite accessible once you actually start coding.

The following page explains the whole process for Django, but the same approach would be applicable to any framework: http://code.djangoproject.com/wiki/Charts.

In particular, note that you can build a graphic in-memory and return it as an HttpResponse. It's quite fast. I use something like the following in one of my apps:

def my_chart(request):
    response = HttpResponse(
        my_function_to_make_a_chart().asString('png'),
        'image/png',
    )
    return response

That django view would be associated with a URL that you would embed directly into your HTML document as an tag:

<img src="/my_site/my_chart/" alt="A cool chart" />
AndrewF
that's interesting,the HttpResponse idea is cool!Just curious is it necessary to use a framework or it is not a lot of code in pure Python
Alexander Ivanov
Generating the chart is just python (using the reportlab library). What are you using now to run your server-side script? Just CGI? It's possible to do so, but a framework handles a lot of the boilerplate for you. You could use Flask if you want something minimal: <http://flask.pocoo.org/>.
AndrewF
Just Python...Flask looks good though
Alexander Ivanov
+1  A: 

For Python - check matplotlib - it should do everything you need to do, including outputting to PNG, JPEG, etc.

Connor M
i checked it,thanks,it look simple and fast
Alexander Ivanov