chaco.scales.time_scale module

A scale for time and calendar intervals.

class chaco.scales.time_scale.CalendarScaleSystem(*scales, **kw)

Bases: chaco.scales.scales.ScaleSystem

Scale system for calendars.

This class has a pre-defined set of nice “time points” to use for ticking and labelling.

class chaco.scales.time_scale.TimeScale(**kw_interval)

Bases: chaco.scales.scales.AbstractScale

A scale based on time intervals and calendar dates. The valid intervals are:

Natural time:

microseconds, milliseconds, seconds, minutes, hours, days, years

Calendar time:

day_of_month, month_of_year

For calendar times, a list of hours/days/months is set. By default, intervals are aligned to January 1st.

CALENDAR_UNITS = ('day_of_month', 'month_of_year')
SECS_PER_UNIT = {'day_of_month': 2592000, 'days': 86400, 'hours': 3600, 'microseconds': 1e-06, 'milliseconds': 0.001, 'minutes': 60, 'month_of_year': 31536000, 'seconds': 1, 'years': 31536000}
cal_ticks(start, end)

ticks() method for calendar-based intervals

label_width(start, end, numlabels=None, char_width=None)

Returns an estimate of total number of characters used by the the labels that this scale will produce for the given set of inputs, as well as the number of labels.

Overrides AbstractScale.

labels(start, end, numlabels=None, char_width=None)

Returns a series of ticks and corresponding strings for labels that fall inside the interval (start,*end*).

Overrides AbstractScale.

num_ticks(start, end, desired_ticks=None)

Returns an approximate number of ticks that this scale produces for the given interval.

Implements AbstractScale.

ticks(start, end, desired_ticks=None)

Returns the set of “nice” positions on this scale that enclose and fall inside the interval (start,*end*).

Implements AbstractScale. The start and end parameters are floating-point seconds since the epoch.

chaco.scales.time_scale.dt_to_sec(t)

Returns the floating point number of seconds since the UNIX epoch corresponding to the given datetime instance.

This value is more accurate than mktime(t.timetuple()) because it preserves milliseconds.

chaco.scales.time_scale.td_to_sec(td)

Returns the floating point number of seconds in a timedelta object.

chaco.scales.time_scale.tfrac(t, **time_unit)

Performs a calendar-aware split of a time into (aligned_time, frac) over an interval that is a multiple of one of the following time units:

“microseconds” “milliseconds”, “seconds”, “minutes”, “hours”, “days”, “years”

Settings of milliseconds..hours are truncated towards 0, days are counted from January 1st of their respective year, and years are counted from 1 AD. This may lead to unexpected rounding if multi-day or multi-year intervals are used.

For example:

If it is currently 4:15pm on January 3rd, 2007, calling: tfrac(time.time(), hours=3) returns the UNIX number of seconds corresponding to “January 3rd, 2007 15:00:00” as the aligned time, and the number of seconds in 1 hour and 15 minutes as the fractional part.

Parameters
  • t (float) – time in seconds

  • **time_unit (dict) – a single (interval=value) item

Returns

A tuple

Return type

(aligned time as UNIX time, remainder in seconds)

chaco.scales.time_scale.trange(start, end, **time_unit)

Like range(), but for times, and with “natural” alignment depending on the interval.

For example:

t_range(time.time(), time.time()+76*3600, days=2)
t_range(start, end, months=3)
Parameters
  • start (float) – Time in seconds. end must be later than start.

  • end (float) – Time in seconds. end must be later than start.

  • time_unit (a single (key, int_value) pair) – The units to use. key must be in the list: “milliseconds”, “seconds”, “minutes”, “hours”, “days”, “months”, “years”. Months are treated as 30 days, and years are treated as 365 days.

Returns

  • A list of times that nicely span the interval, or an empty list if *start*

  • and *end fall within the same interval.*