@header@
 
 
matplotlib.dates
index
/usr/local/lib/python2.3/site-packages/matplotlib/dates.py

The dates module is built around the assumption that users will want
to specify dates in a variety of ways.
 
The goal of the converter classes defined here is to hide all the
conversions required to plot data on the screen from you, and to
provide an abstract interface to matplotlib plotting routines so you
can use date instances of your choice.  You pass these converter
classes to date plotting functions and these functions will do the
rest.
 
The following converters are provided
 
    * EpochConverter      - dates are seconds since the epoch
 
    * PyDatetimeConverter - dates are python2.3 date/datetime instances
 
    * MxDatetimeConverter - dates are egenix mx.Datetime instances
 
You can provide your own converter by deriving from the base class
DateConverter and overriding the methods epoch and from_epoch.  If you
define one for a widely used date class, or extend the ones here,
please contribute the code back!  All conversions are done to and from
seconds since the epoch locatime.
 
Here is an example of how you could plot dates with python datetime
instances in the eastern time zone::
 
  from matplotlib.dates import PyDatetimeConverter, Eastern
  from matplotlib.matlab import *
  
  dates = [ dt1, dt2, dt2, ...]     # the datetime instances
  vals  = [ val1, val2, val3, ...]  # the y values
  converter = PyDatetimeConverter(Eastern)  # dates are in Eastern tz
  ax = subplot(111)
  plot_date(dates, vals, converter)
 
The matplotlib.ticker module provides many custom tick locators and
formatters for you so you don't have to work at the level of
manipulating epoch seconds to set your ticks.  Eg, to set the ticks on
the years, you would do::
 
    from matplotlib.ticker import YearLocator
 
    ... your plot here ...
    years = YearLocator(5)   # every 5 years
    ax.xaxis.set_major_locator(years)
 
and the date tick locator will try and pick the best axis range and
tick locations for you, ie, on multiples of 5 years.  Although the
default choices will probably be good, if you are unhappy with the
range choices the locator makes for you, you can use your date
instances and converter to specify them yourself, as in::
 
  dmin = converter( datetime(2002,01,15) )
  dmax = converter( datetime(2004,01,15) )
  ax.set_xlim( (dmin, dmax) )
 
Use date formatters to specify major and minor tick formats.  Minor
ticks are off by default, but you can turn them on by passing a date
locator and date formatter to the axis.  The relevant methods are::
 
  ax.xaxis.set_major_locator( majLocator )
  ax.xaxis.set_major_formatter( majFormatter )
 
  ax.xaxis.set_minor_locator( minLocator )
  ax.xaxis.set_minor_formatter( minFormatter )
 
where majLocator and minLocator are matplotlib.ticker.Locator instance
and majFormatter and minFormatter are matplotlib.ticker.Formatter
instances.  Many date locators are provided: MinuteLocator,
HourLocator, DayLocator, WeekdayLocator, MonthLocator, YearLocator.
Most of these take an argument to, for example, select only hours or
years that are multiples of some number.  The DateFormatter class
takes a strftime format string to format the dates on the major and
minor ticker.  The minor ticker is off by default in all plots so you
will need to set the minor locator if you want to turn them on, and
the minor formatter if you want to label them.
 
Here is an example setting the major date formatter
strftime string, as in::
 
    formatter = DateFormatter('%Y')
    ax.xaxis.set_major_formatter(formatter)
 
See the examples/dates*.py in the matplotlib src distribution for
complete demos, and the matplotlib.ticker help for more information on
tick locators and formatters.

 
Modules
       
time
math
mx
os
sys
time

 
Classes
       
DateConverter
EpochConverter
MxDatetimeConverter
PyDatetimeConverter
datetime.tzinfo(__builtin__.object)
FixedOffset
LocalTimezone
USTimeZone
UTC

 
class DateConverter
    An abstract class to allow users to specify dates however they
want.  The class provides a standard set of calls which take the
users date instance and convert to to the output indicated.  This
allows you to store dates as mx datetimes, python datetimes,
epochs etc.
 
  Methods defined here:
__call__(self, x)
convert userland datetime instance x to epoch
add_month(self, x, direction=1)
return now plus one month as epoch
add_year(self, x, direction=1)
return now plus one year as epoch
ceil_day(self, x)
return the ceiled day
ceil_hour(self, x)
return the ceiled hour as epoch
ceil_minute(self, x)
return the ceiled minute
ceil_month(self, x)
return the ceiled month
ceil_year(self, x)
return the ceiled year
day_of_week(self, x)
return day of week; monday is 0
epoch(self, x)
convert userland datetime instance x to epoch
floor_day(self, x)
return the floored day
floor_hour(self, x)
return the floored hour as epoch
floor_minute(self, x)
return the floored minute
floor_month(self, x)
return the floored month
floor_year(self, x)
return the floored year
from_epoch(self, e)
return an instance of your date from the epoch
hms(self, x)
return the hour, minute, second
strftime(self, fmt, x)
format x using strftime format string fmt
strptime(self, datestr, fmt)
return an instance of your date from a date string and fouermat
ymd(self, x)
return the year month day. month and day are indexed from 1
ymdhms_to_epoch(self, year, month, day, hour, minute, second)

 
class EpochConverter(DateConverter)
    Represent time in the epoch
 
  Methods defined here:
ceil_day(self, x)
return the ceiled day
ceil_hour(self, x)
return the ceiled hour
ceil_minute(self, x)
return the ceiled minute
day_of_week(self, x)
return day of week; monday is 0
epoch(self, x)
convert userland datetime instance x to epoch
floor_day(self, x)
return the floored day
floor_hour(self, x)
return the floored hour
floor_minute(self, x)
return the floored minute
from_epoch(self, e)
return an instance of your date from the epoch
hms(self, x)
return the hour, minute, second
strftime(self, fmt, x)
format x using strftime format string fmt
strptime(self, datestr, fmt)
return an instance of your date from a date string and format
ymd(self, x)
return the year month day. month and day are indexed from 1

Methods inherited from DateConverter:
__call__(self, x)
convert userland datetime instance x to epoch
add_month(self, x, direction=1)
return now plus one month as epoch
add_year(self, x, direction=1)
return now plus one year as epoch
ceil_month(self, x)
return the ceiled month
ceil_year(self, x)
return the ceiled year
floor_month(self, x)
return the floored month
floor_year(self, x)
return the floored year
ymdhms_to_epoch(self, year, month, day, hour, minute, second)

 
class FixedOffset(datetime.tzinfo)
    Fixed offset in minutes east from UTC.
 
 
Method resolution order:
FixedOffset
datetime.tzinfo
__builtin__.object

Methods defined here:
__init__(self, offset, name)
dst(self, dt)
tzname(self, dt)
utcoffset(self, dt)

Data and other attributes defined here:
__dict__ = <dictproxy object>
dictionary for instance variables (if defined)
__weakref__ = <attribute '__weakref__' of 'FixedOffset' objects>
list of weak references to the object (if defined)

Methods inherited from datetime.tzinfo:
__getattribute__(...)
x.__getattribute__('name') <==> x.name
__reduce__(...)
-> (cls, state)
fromutc(...)
datetime in UTC -> datetime in local time.

Data and other attributes inherited from datetime.tzinfo:
__new__ = <built-in method __new__ of type object>
T.__new__(S, ...) -> a new object with type S, a subtype of T

 
class LocalTimezone(datetime.tzinfo)
    
Method resolution order:
LocalTimezone
datetime.tzinfo
__builtin__.object

Methods defined here:
dst(self, dt)
tzname(self, dt)
utcoffset(self, dt)

Data and other attributes defined here:
__dict__ = <dictproxy object>
dictionary for instance variables (if defined)
__weakref__ = <attribute '__weakref__' of 'LocalTimezone' objects>
list of weak references to the object (if defined)

Methods inherited from datetime.tzinfo:
__getattribute__(...)
x.__getattribute__('name') <==> x.name
__reduce__(...)
-> (cls, state)
fromutc(...)
datetime in UTC -> datetime in local time.

Data and other attributes inherited from datetime.tzinfo:
__new__ = <built-in method __new__ of type object>
T.__new__(S, ...) -> a new object with type S, a subtype of T

 
class MxDatetimeConverter(DateConverter)
    Convert egenix mx.Datetime instances
 
  Methods defined here:
epoch(self, x)
convert userland datetime instance x to epoch
from_epoch(self, e)
return an instance of your date from the epoch

Methods inherited from DateConverter:
__call__(self, x)
convert userland datetime instance x to epoch
add_month(self, x, direction=1)
return now plus one month as epoch
add_year(self, x, direction=1)
return now plus one year as epoch
ceil_day(self, x)
return the ceiled day
ceil_hour(self, x)
return the ceiled hour as epoch
ceil_minute(self, x)
return the ceiled minute
ceil_month(self, x)
return the ceiled month
ceil_year(self, x)
return the ceiled year
day_of_week(self, x)
return day of week; monday is 0
floor_day(self, x)
return the floored day
floor_hour(self, x)
return the floored hour as epoch
floor_minute(self, x)
return the floored minute
floor_month(self, x)
return the floored month
floor_year(self, x)
return the floored year
hms(self, x)
return the hour, minute, second
strftime(self, fmt, x)
format x using strftime format string fmt
strptime(self, datestr, fmt)
return an instance of your date from a date string and fouermat
ymd(self, x)
return the year month day. month and day are indexed from 1
ymdhms_to_epoch(self, year, month, day, hour, minute, second)

 
class PyDatetimeConverter(DateConverter)
    Convert python2.3 date or datetime instances
 
  Methods defined here:
day_of_week(self, x)
return day of week; monday is 0
epoch(self, x)
convert userland datetime instance x to epoch
from_epoch(self, e)
return an instance of your date from the epoch
hms(self, x)
return the hour, minute, second
strftime(self, fmt, x)
format x using strftime format string fmt
strptime(self, datestr, fmt)
return an instance of your date from a date string and format
ymd(self, x)
return the year month day. month and day are indexed from 1

Methods inherited from DateConverter:
__call__(self, x)
convert userland datetime instance x to epoch
add_month(self, x, direction=1)
return now plus one month as epoch
add_year(self, x, direction=1)
return now plus one year as epoch
ceil_day(self, x)
return the ceiled day
ceil_hour(self, x)
return the ceiled hour as epoch
ceil_minute(self, x)
return the ceiled minute
ceil_month(self, x)
return the ceiled month
ceil_year(self, x)
return the ceiled year
floor_day(self, x)
return the floored day
floor_hour(self, x)
return the floored hour as epoch
floor_minute(self, x)
return the floored minute
floor_month(self, x)
return the floored month
floor_year(self, x)
return the floored year
ymdhms_to_epoch(self, year, month, day, hour, minute, second)

 
class USTimeZone(datetime.tzinfo)
    
Method resolution order:
USTimeZone
datetime.tzinfo
__builtin__.object

Methods defined here:
__init__(self, hours, reprname, stdname, dstname)
__repr__(self)
dst(self, dt)
tzname(self, dt)
utcoffset(self, dt)

Data and other attributes defined here:
__dict__ = <dictproxy object>
dictionary for instance variables (if defined)
__weakref__ = <attribute '__weakref__' of 'USTimeZone' objects>
list of weak references to the object (if defined)

Methods inherited from datetime.tzinfo:
__getattribute__(...)
x.__getattribute__('name') <==> x.name
__reduce__(...)
-> (cls, state)
fromutc(...)
datetime in UTC -> datetime in local time.

Data and other attributes inherited from datetime.tzinfo:
__new__ = <built-in method __new__ of type object>
T.__new__(S, ...) -> a new object with type S, a subtype of T

 
class UTC(datetime.tzinfo)
    UTC
 
 
Method resolution order:
UTC
datetime.tzinfo
__builtin__.object

Methods defined here:
dst(self, dt)
tzname(self, dt)
utcoffset(self, dt)

Data and other attributes defined here:
__dict__ = <dictproxy object>
dictionary for instance variables (if defined)
__weakref__ = <attribute '__weakref__' of 'UTC' objects>
list of weak references to the object (if defined)

Methods inherited from datetime.tzinfo:
__getattribute__(...)
x.__getattribute__('name') <==> x.name
__reduce__(...)
-> (cls, state)
fromutc(...)
datetime in UTC -> datetime in local time.

Data and other attributes inherited from datetime.tzinfo:
__new__ = <built-in method __new__ of type object>
T.__new__(S, ...) -> a new object with type S, a subtype of T

 
Functions
       
first_sunday_on_or_after(dt)

 
Data
        Central = Central
DSTDIFF = datetime.timedelta(0, 3600)
DSTEND = datetime.datetime(1, 10, 25, 1, 0)
DSTOFFSET = datetime.timedelta(-1, 68400)
DSTSTART = datetime.datetime(1, 4, 1, 2, 0)
Eastern = Eastern
FRIDAY = 4
HOUR = datetime.timedelta(0, 3600)
Local = <matplotlib.dates.LocalTimezone object>
MONDAY = 0
Mountain = Mountain
Pacific = Pacific
SATURDAY = 5
SEC_PER_DAY = 86400
SEC_PER_HOUR = 3600
SEC_PER_MIN = 60
SEC_PER_WEEK = 604800
STDOFFSET = datetime.timedelta(-1, 64800)
SUNDAY = 6
THURSDAY = 3
TUESDAY = 1
WEDNESDAY = 2
WEEKDAYS = (0, 1, 2, 3, 4, 5, 6)
ZERO = datetime.timedelta(0)
__warningregistry__ = {('integer multiplication', <class exceptions.OverflowWarning>, 158): 1, ('integer multiplication', <class exceptions.OverflowWarning>, 160): 1}
division = _Feature((2, 2, 0, 'alpha', 2), (3, 0, 0, 'alpha', 0), 8192)
utc = <matplotlib.dates.UTC object>
@footer@