chaco.scales.formatters module

Classes for formatting labels for values or times.

class chaco.scales.formatters.BasicFormatter(**kwds)

Bases: object

Formatter for numeric labels.

avg_label_width = 7.0
estimate_width(start, end, numlabels=None, char_width=None, fill_ratio=0.3, ticker=None)

Returns an estimate of the total number of characters used by the the labels for the given set of inputs, as well as the number of labels.

Parameters
  • start (number) – The beginning of the interval.

  • end (number) – The end of the interval.

  • numlabels (number) – The ideal number of labels to generate on the interval.

  • char_width (number) – The total character width available for labelling the interval.

  • fill_ratio (0.0 < float <= 1.0) – Ratio of the available width that will be occupied by label text.

  • ticker (AbstractScale object) – Object that can calculate the number of labels needed.

Returns

Return type

(numlabels, total label width)

format(ticks, numlabels=None, char_width=None, fill_ratio=0.3)

Does “nice” formatting of floating-point numbers. numlabels is ignored in this method.

oldformat(ticks, numlabels=None, char_width=None)

This function is adapted from matplotlib’s “OldScalarFormatter”.

Parameters
  • ticks (array of numbers) – The tick values to be formatted.

  • numlabels – Not used.

  • char_width – Not used.

Returns

Return type

List of formatted labels.

scientific_limits = (-3, 5)
use_scientific = True
class chaco.scales.formatters.IntegerFormatter(**kwds)

Bases: chaco.scales.formatters.BasicFormatter

Format integer tick labels as integers.

format(ticks, numlabels=None, char_width=None, fill_ratio=0.3)

Formats integer tick labels.

class chaco.scales.formatters.NullFormatter

Bases: object

Formatter for empty labels.

estimate_width(end, numlabels=None, char_width=None)

Returns 0 for width and 0 for number of labels.

format(numlabels=None, char_width=None)

Returns a list containing an empty label for each item in ticks.

class chaco.scales.formatters.OffsetFormatter(**kwds)

Bases: chaco.scales.formatters.BasicFormatter

This formatter is like BasicFormatter, but it supports formatting ticks using an offset. This is useful for viewing small ranges within big numbers.

end_label_format = 'offset'
estimate_width(start, end, numlabels=None, char_width=None, fill_ratio=0.3, ticker=None)

Returns an estimate of the total number of characters used by the the labels for the given set of inputs, as well as the number of labels.

Parameters
  • start (number) – The beginning of the interval.

  • end (number) – The end of the interval.

  • numlabels (number) – The ideal number of labels to generate on the interval.

  • char_width (number) – The total character width available for labelling the interval.

  • fill_ratio (0.0 < float <= 1.0) – Ratio of the available width that will be occupied by label text.

  • ticker (AbstractScale object) – Object that can calculate the number of labels needed.

Returns

Return type

(numlabels, total label width)

format(ticks, numlabels=None, char_width=None)

Does “nice” formatting of floating-point numbers. numlabels is ignored in this method.

offset = None
offset_display = 'firstlast'
offset_format = 'sci'
offset_limits = (-3, 4)
offset_threshold = 0.001
use_offset = False
class chaco.scales.formatters.TimeFormatter(**kwds)

Bases: object

Formatter for time values.

estimate_width(start, end, numlabels=None, char_width=None, fill_ratio=0.2, ticker=None)

Returns an estimate of the total number of characters used by the the labels for the given set of inputs, as well as the number of labels.

Parameters
  • start (number) – The beginning of the interval.

  • end (number) – The end of the interval.

  • numlabels (number) – The ideal number of labels to generate on the interval.

  • char_width (number) – The total character width available for labelling the interval.

  • fill_ratio (0.0 < float <= 1.0) – Ratio of the available width that will be occupied by label text.

  • ticker (AbstractScale object) – Object that can calculate the number of labels needed.

Returns

Return type

(numlabels, total label width)

format(ticks, numlabels=None, char_width=None, fill_ratio=0.3, ticker=None)

Formats a set of time values.

Parameters
  • ticks (array of numbers) – The tick values to be formatted

  • numlabels – Not used.

  • char_width (number) – The total character width available for labelling the interval.

  • fill_ratio (0.0 < float <= 1.0) – Ratio of the available width that will be occupied by label text.

  • ticker (AbstractScale object) – Object that can calculate the number of labels needed.

Returns

Return type

List of formatted labels.

format_order = ['microseconds', 'milliseconds', 'seconds', 'minsec', 'minutes', 'hourmin', 'hours', 'days', 'months', 'years']
formats = {'days': (array([5, 5]), ('%m/%d', '%a%d')), 'hourmin': (array([5]), ('%H:%M',)), 'hours': (array([3, 5]), ('%Hh', '%H:%M')), 'microseconds': (array([5, 9]), ('%(us)us', '%(ms_).%(us)ms')), 'milliseconds': (array([5, 7]), ('%(ms)ms', '%S.%(ms)s')), 'minsec': (array([5]), ('%M:%S',)), 'minutes': (array([3]), ('%Mm',)), 'months': (array([7, 5]), ('%m/%Y', '%b%y')), 'seconds': (array([3, 3]), (':%S', '%Ss')), 'years': (array([3, 4]), (<function _two_digit_year>, <function _four_digit_year>))}
strip_leading_zeros = True
chaco.scales.formatters.strftimeEx(fmt, t, timetuple=None)

Extends time.strftime() to format milliseconds and microseconds.

Expects input to be a floating-point number of seconds since epoch. The additional formats are:

  • %(ms): milliseconds (uses round())

  • %(ms_): milliseconds (uses floor())

  • %(us): microseconds (uses round())

The format may also be a callable which will bypass time.strftime() entirely.