I wrote this to get familiar with GTK, Glade and matplotlib. This post is not a walkthrough or tutorial of using either of them. I wanted to write down some notes. The Flu Data Viewer is an example or a code I could copy from for other coding (So this code is put in Public Domain), so it would unlikely be updated in the future. The flu data is from Google Flu Trends.

This program draws one or more countries flu data in one figure. It downloads data from Google and saves data to fludata.csv in current directory. I was thinking to do some process, but I didnt know what I can do and I wasnt really interested in this.

Here is a screenshot:


You can download the code at Google Code.

1   Window.visible

When I first time use Glade to create the UI, I didnt know the window.visible is False by default, so you have to either set it in Glade or run window.show().

2   gtk.glade.XML(gladefile, windowname)

windowname must match window.name in Glade. Its obvious but I thought one Glade XML one window, I set it to something else, therefore my window never show up. One Glade XML could have many windows.

3   missing int type data in csv

3.1   Loading using matplotlib.mlab.csv2rec

d = dict(zip(fields, [lambda value: int(value) if value != '' else nan]*len(fields)))
self.rec = mlab.csv2rec(CSV_FILENAME, converterd=d)

Where fields is a list of field names. If a data is missing, it will be an empty string '', I think using NaN (Not a Number, numpy.nan) may be a better idea to represent it than 0 (zero).

There is another way to deal with missing data by giving missingd to csv2rec, but the version of matplotlib on my computer doesnt have it. It should like converterd but with values which you want to assign when data is missing.

3.2   Feeding to gtk.TreeView

If you set int type to gtk.ListStore, then it will not accept numpy.nan. So str type may be okay to use.

4   Multiselection mode in gtk.TreeView


5   Dont forget NavigationToolbar

Users still need a way to zoom in/out.

from matplotlib.backends.backend_gtkagg import NavigationToolbar2GTKAgg as NavigationToolbar

vbox.pack_start(canvas, True, True)
vbox.pack_start(NavigationToolbar(canvas, window), False, False)

I hope I could find a way to do data line tracing. Its hard to tell Y=? when X=123.