DateLocator() woes



    > Does anyone know what might be the problem with the
    > datelocator() as I've done it?

If you look at the documentation for the DateLocator

you'll see that it takes a single argument in the init function which
is a timezone. You are passing it (min-max)/8.0 which in my guess
does not evaluate to a timezone unless you are deep into overload
magic <wink>

DateLocator is base class and you will need to instantiate one of the
derived classes (eg MonthLocator). What plot_date does is inspect the
date range and try to make an intelligent guess about which kind of
locator you need. I just factored this code into a reusable date
locator/formatter factory function which is in CVS

  Checking in lib/matplotlib/;
  /cvsroot/matplotlib/matplotlib/lib/matplotlib/,v <--
  new revision: 1.12; previous revision: 1.11

I'll post it here in case you don't have access to CVS and just want
to plug it into your application

import math
from matplotlib.dates import YearLocator, MonthLocator, WeekdayLocator, \
     DayLocator, HourLocator, MinuteLocator, DateFormatter

def date_ticker_factory(span, tz=None, numticks=5):
    Create a date locator with numticks (approx) and a date formatter
    for span in days. Return value is (locator, formatter)
    if span==0: span = 1/24.

    minutes = span*24*60
    hours = span*24
    days = span
    weeks = span/7.
    months = span/31. # approx
    years = span/365.

    if years>numticks:
        locator = YearLocator(int(years/numticks), tz=tz) # define
        fmt = '%Y'
    elif months>numticks:
        locator = MonthLocator(tz=tz)
        fmt = '%b %Y'
    elif weeks>numticks:
        locator = WeekdayLocator(tz=tz)
        fmt = '%a, %b %d'
    elif days>numticks:
        locator = DayLocator(interval=int(math.ceil(days/numticks)), tz=tz)
        fmt = '%b %d'
    elif hours>numticks:
        locator = HourLocator(interval=int(math.ceil(hours/numticks)), tz=tz)
        fmt = '%H:%M\n%b %d'
    elif minutes>numticks:
        locator = MinuteLocator(interval=int(math.ceil(minutes/numticks)), tz=tz)
        fmt = '%H:%M:%S'
        locator = MinuteLocator(tz=tz)
        fmt = '%H:%M:%S'

    formatter = DateFormatter(fmt, tz=tz)
    return locator, formatter

locator, formatter = date_ticker_factory(2000, numticks=8)
print locator, formatter

Hi again, I'm just tinkering around with py2exe and matplotlib. I
attached a very short script and the setup file I'm using and the errlog
that results. I don't understand quite what this means or how to get
this to work. I checked out the setup file at:

But I haven't had any luck getting it to work. How do I make this thing
go? Thanks.

Jeff (440 Bytes) (1.04 KB) (988 Bytes)

errlog.txt (321 Bytes)