[reportlab-users] Question about passing function to labelTextFormat

reportlab-users@reportlab.com reportlab-users@reportlab.com
Tue, 16 Sep 2003 16:59:30 -0400 (EDT)


Hi-

I have been making lineplots of time series data by converting the dates
to integers, where 1 is the beginning of the date range I want to graph.

For example, if I want to plot a series from November, 1999 to March,
2000, then I convert:

November, 1999 => 1
December, 1999 => 2
January, 2000 => 3
Februrary, 2000 => 4
March, 2000 => 5

You get the idea.

Then, to print x-axes with the dates, I wrote this function:

def mk_date_labels(i):
    dates = ['November, 1999', 'December, 1999', ... ] #you get the idea
    return dates[i]

Then I have been passing this function to
reportlab.graphics.charts.axes.XValueAxis.labelTextFormat like so:

lp.xValueAxis.labelTextFormat = num2str #lp is my LinePlot() object

This is great, but I want to change the mk_date_labels to get 2 args: the
indexing number, and also, the list to use to get the text string.  How do
I write the function that way?  I don't know enough about passing
functions as parameters to figure it out.