chaco.scales.scales module

Functions and classes that compute ticks and labels for graph axes, with special handling of time and calendar axes.

class chaco.scales.scales.AbstractScale

Bases: object

Defines the general interface for scales.

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

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

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

  • end (number) – The end of the scale 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.

Returns

Return type

(numlabels, total label width)

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*).

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

  • end (number) – The end of the scale 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.

  • of numlabels or char_width must be provided. If both are (One) –

  • provided

  • both are considered when picking label density and format. (then) –

num_ticks(start, end, desired_ticks=None)

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

This method is used by the scale system to determine whether this is the appropriate scale to use for an interval; the returned number of ticks does not have to be exactly the same as what ticks() returns.

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

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

  • desired_ticks (integer) – Number of ticks that the caller would like to get

Returns

Return type

A float or an integer.

ticks(start, end, desired_ticks=None)

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

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

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

  • desired_ticks (integer) – Number of ticks that the caller would like to get

class chaco.scales.scales.DefaultScale(formatter=None)

Bases: chaco.scales.scales.AbstractScale

A dynamic scale that tries to place ticks at nice numbers (1, 2, 5, 10) so that ticks don’t “pop” as the resolution changes.

num_ticks(start, end, desired_ticks=8)

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

Implements AbstractScale.

ticks(start, end, desired_ticks=8)

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

Implements AbstractScale.

class chaco.scales.scales.FixedScale(resolution, zero=0.0, formatter=None)

Bases: chaco.scales.scales.AbstractScale

A scale with fixed resolution, and “nice” points that line up at multiples of the resolution. An optional zero value can be defined that offsets the “nice” points to (N*resolution+zero).

num_ticks(start, end, desired_ticks=None)

For FixedScale, desired_ticks is ignored.

Overrides AbstractScale.

ticks(start, end, desired_ticks=None)

For FixedScale, desired_ticks is ignored.

Overrides AbstractScale.

class chaco.scales.scales.LogScale(formatter=None)

Bases: chaco.scales.scales.AbstractScale

A dynamic scale that only produces ticks and labels that work well when plotting data on a logarithmic scale.

num_ticks(start, end, desired_ticks=8)

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

Implements AbstractScale.

ticks(start, end, desired_ticks=8)

Compute a “nice” set of ticks for a log scale.

class chaco.scales.scales.Pow10Scale(formatter=None)

Bases: chaco.scales.scales.AbstractScale

A dynamic scale that shows only whole multiples of powers of 10 (including powers < 1).

num_ticks(start, end, desired_ticks=8)

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

Implements AbstractScale.

ticks(start, end, desired_ticks=8)

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

Implements AbstractScale.

class chaco.scales.scales.ScaleSystem(*scales, **kw)

Bases: object

Represents a collection of scales over some range of resolutions.

This class has settings for a default scale that is used when ticking an interval that is smaller than the finest resolution scale or larger than the coarsest resolution scale.

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

Computes position and labels for an interval

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

  • end (number) – The end of the scale 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.

  • of numlabels or char_width must be provided. If both are (One) –

  • provided

  • both are considered when picking label density and format. (then) –

Returns

Return type

A list of (tick position, string) tuples.

ticks(start, end, numticks=None)

Computes nice locations for tick marks.

Parameters
  • start (number) – The start and end values of the data.

  • end (number) – The start and end values of the data.

  • numticks (number) – The desired number of ticks to produce.

  • scales (a list of tuples of (min_interval, Scale)) – Scales to use, in order from fine resolution to coarse. If the end-start interval is less than a particular scale’s min_interval, then the previous scale is used.

Returns

Return type

A list of positions where the ticks are to be placed.

chaco.scales.scales.frange(min, max, delta)

Floating point range.

chaco.scales.scales.heckbert_interval(data_low, data_high, numticks=8, nicefunc=<function _nice>, enclose=False)

Returns a “nice” range and resolution for an interval and a preferred number of ticks, using Paul Heckbert’s algorithm in Graphics Gems.

If enclose is True, then the function returns a min and a max that fall inside data_low and data_high; if enclose is False, the nice interval can be larger than the input interval.