[SciPy-user] time series plotting (slightly off topic)
Matt Knox
mattknox_ca at hotmail.com
Tue Jan 2 14:26:42 EST 2007
>
> Ciao Matt,
> Happy New Year !
> I've been quite busy during Xmas and NYD with your TimeSeries module. Please
> have a look in the mtimeseries subfolder. You'll find the basic code along
> with an updated version of your example and some unittests.
Thanks. Happy new year to you too. Hope you found some time to relax during the
holiday season too! I'll take a look at your changes.
> which means that plotting is as simple as:
> plot_date(series._dates.toordinal(), series._series)
> I had already written some subclasses of MPL.SubPlot to simplify that. I'll
> have to clean my code a bit and will post it latter.
>
My first attempt at plotting the time series objects was similar to this, but I
found getting intelligent labels quite tricky. My new plotting code basically
bypasses the built-in matplotlib date axis labelling and outputs the labels
from scratch using my own logic (which works better for handling different
frequencies in my opinion). A lot of the logic I created concerns the spacing
of the labels and how many labels to draw, so you don't end up with an over-
crowded axis. And quarterly frequency labelling is supported, which I believe
is not possible (not easily anyway) with the standard stuff.
> A couple of comments:
> - Do we still need dateOf ? cseries.convert seems to do the work. dateOf
could then just be a python wrapper.
Yeah, you are probably right. Originally all the logic was not implemented in C
yet, so I needed this function. The name of the function (dateOf) probably
isn't entirely intuitive either. The reason for the name is because that's what
the equivalent function in FAME is called and I just named it the same :)
> - It'd be cool if cseries.convert could accept arrays instead of only
scalars.
> That way, we wouldn't have to loop over a DateArray for the conversion.
>
Yeah, that could be done. Wouldn't be very difficult likely.
> I want also to work on supporting other frequencies, such as weekly, hourly
> and minutely. There's already some basic implementation in tsdate, but I
> haven't tried to modify the C code yet.
As you are aware, weekly is one of those tricky frequencies that isn't a nice
subset of the other frequencies. It's not a data frequency I use very often,
but we'll probably need to discuss some strategy for converting it to other
frequencies since it is an odd-ball case. Another thing to consider with weekly
frequency is defining when the week ends at. FAME actually recognizes seven
different weekly frequencies: weekly(Monday), weekly(Tuesday), etc... , and
this impacts how frequency conversion is done too. It's not really something I
care too much about, but just something to consider...
Also, looking at your code for the weekly frequency in tsdate... I think it
might be a good idea to add an additional parameter to the __init__ method
called "period" so you could specify a date with just the year and period (15th
week for example, or maybe -1 for last period in year, etc).
- Matt
More information about the SciPy-User
mailing list