On Tue, Apr 7, 2009 at 4:29 PM, Jae-Joon Lee <lee.j.joon@gmail.com> wrote:

You can also do this without converting to ordinal by hand:

from datetime import datetime, timedelta

today = datetime.today()

xvals = [today + timedelta(seconds=s) for s in range(1200)]

# Matplotlib can use lists, but you can also make this into a numpy object array

xvals = np.array(xvals)

Since matplotlib's date formatter and locator require absolute times, you could also just make your own locator and formatter functions for your relative time values:

import matplotlib.ticker as mticker

def minsec(sec, unused):

minutes = sec // 60

sec = sec - minutes * 60

return '%d:%02d' % (minutes, sec)

locator = mticker.MultipleLocator(60)

formatter = mticker.FuncFormatter(minsec)

RyanHi,

I'm not a frequent user of matplotlib.dates module, so other expert

may give you a better answer.

My understanding is that, for the date time formatting, the (x-) data

needs to be days (if not datetime instance) from some reference point

(1, 1, 1? I'm not sure).

The easiest way I can think of in your case is

from matplotlib.dates import datetime, SEC_PER_DAY

ordinal_today=datetime.datetime.today().toordinal()

xvals = ordinal_today + np.arange(1200, dtype="d")/SEC_PER_DAY

You can also do this without converting to ordinal by hand:

from datetime import datetime, timedelta

today = datetime.today()

xvals = [today + timedelta(seconds=s) for s in range(1200)]

# Matplotlib can use lists, but you can also make this into a numpy object array

xvals = np.array(xvals)

Since matplotlib's date formatter and locator require absolute times, you could also just make your own locator and formatter functions for your relative time values:

import matplotlib.ticker as mticker

def minsec(sec, unused):

minutes = sec // 60

sec = sec - minutes * 60

return '%d:%02d' % (minutes, sec)

locator = mticker.MultipleLocator(60)

formatter = mticker.FuncFormatter(minsec)

--

Ryan May

Graduate Research Assistant

School of Meteorology

University of Oklahoma

Sent from Enterprise, AL, United States