Wednesday, August 12, 2009

Graphing in Python

To begin, let me explain the project briefly: I set out with this project to learn a little more about grabbing data from the web, processing csv/xls, and most importantly graphing in Python. I decided to investigate the question of whether gas and oil prices are tied very closely because we all notice how much gas jumps up and for apparently no reason. For more information about the results see my Sugary Donut blog entry.

What I want to discuss here is Python's graphing capabilities. There are no language features for it, but plenty of people have developed libraries for it. I initially considered cairoplot and matplotlib but dismissed them as being "too big and complicated." I wanted something simple, quick, and without dependent packages. gnuplot got rejected for similar reasons as well as just not looking cool enough (imagine that, an ugly gnu tool *rolls eyes*). I initially started with PyGoogleChart and I immediately hit the problem that the graphs were of limited (re: poor) quality. This made me move onto PyChart, which looked like a well maintained project. I again ran into graphs of small size but also had trouble displaying the data in the way needed. The largest stumbling block was getting the dates to display along the bottom. I found examples of this convoluted solution of associating values with each date (so the values are plotted and the dates become the labels along the axis) on the PyChart website. However, I never really got this to work the way I wanted and it felt like a hack.... the back kind. Thus I gave in and decided to give matplotlib a try and I wish I had chosen it to begin with. It easily handled date data for one of the axes and required no coaxing or hacks to get the graph I needed.

My complaint with matplotlib (as well as the others) is poor documentation. There's no "here's the easy explanation of how to do this stuff." To get the matplotlib stuff finalized I had to dig through FAQs, various examples, and the API documentation just to get a simple graph to look the way I wanted it to. Yuck.

Check out the code