chaco.ticks module

Tick generator classes and helper functions for calculating axis tick-related values (i.e., bounds and intervals).

class chaco.ticks.AbstractTickGenerator

Bases: traits.has_traits.HasTraits

Abstract class for tick generators.

get_ticks(data_low, data_high, bounds_low, bounds_high, interval, use_endpoints=False, scale='linear')

Returns a list of ticks points in data space.

Parameters
  • data_low (float) – The actual minimum and maximum of index values of the entire dataset.

  • data_high (float) – The actual minimum and maximum of index values of the entire dataset.

  • bounds_low ("auto", "fit", float) – The range for which ticks should be generated.

  • bounds_high ("auto", "fit", float) – The range for which ticks should be generated.

  • interval ("auto", float) – If the value is a positive number, it specifies the length of the tick interval; a negative integer specifies the number of tick intervals; ‘auto’ specifies that the number and length of the tick intervals are automatically calculated, based on the range of the axis.

  • use_endpoints (Boolean) – If True, the lower and upper bounds of the data are used as the lower and upper end points of the axis. If False, the end points might not fall exactly on the bounds.

  • scale ('linear' or 'log') – The type of scale the ticks are for.

Returns

tick_list – Where ticks are to be placed.

Return type

array of floats

Example

If the range of x-values in a line plot span from -15.0 to +15.0, but the plot is currently displaying only the region from 3.1 to 6.83, and the user wants the interval to be automatically computed to be some nice value, then call get_ticks() thusly:

get_ticks(-15.0, 15.0, 3.1, 6.83, "auto")

A reasonable return value in this case would be:

[3.5, 4.0, 4.5, 5.0, 5.5, 6.0, 6.5]
class chaco.ticks.DefaultTickGenerator

Bases: chaco.ticks.AbstractTickGenerator

An implementation of AbstractTickGenerator that simply uses the auto_ticks() and log_auto_ticks() functions.

get_ticks(data_low, data_high, bounds_low, bounds_high, interval, use_endpoints=False, scale='linear')

Returns a list of ticks points in data space.

Parameters
  • data_low (float) – The actual minimum and maximum of index values of the entire dataset.

  • data_high (float) – The actual minimum and maximum of index values of the entire dataset.

  • bounds_low ("auto", "fit", float) – The range for which ticks should be generated.

  • bounds_high ("auto", "fit", float) – The range for which ticks should be generated.

  • interval ("auto", float) – If the value is a positive number, it specifies the length of the tick interval; a negative integer specifies the number of tick intervals; ‘auto’ specifies that the number and length of the tick intervals are automatically calculated, based on the range of the axis.

  • use_endpoints (Boolean) – If True, the lower and upper bounds of the data are used as the lower and upper end points of the axis. If False, the end points might not fall exactly on the bounds.

  • scale ('linear' or 'log') – The type of scale the ticks are for.

Returns

tick_list – Where ticks are to be placed.

Return type

array of floats

Example

If the range of x-values in a line plot span from -15.0 to +15.0, but the plot is currently displaying only the region from 3.1 to 6.83, and the user wants the interval to be automatically computed to be some nice value, then call get_ticks() thusly:

get_ticks(-15.0, 15.0, 3.1, 6.83, "auto")

A reasonable return value in this case would be:

[3.5, 4.0, 4.5, 5.0, 5.5, 6.0, 6.5]
class chaco.ticks.MinorTickGenerator

Bases: chaco.ticks.DefaultTickGenerator

An implementation of AbstractTickGenerator that extends DefaultTickGenerator, but sets the tick interval to a smaller length.

get_ticks(data_low, data_high, bounds_low, bounds_high, interval, use_endpoints=False, scale='linear')

Returns a list of ticks points in data space.

Parameters
  • data_low (float) – The actual minimum and maximum of index values of the entire dataset.

  • data_high (float) – The actual minimum and maximum of index values of the entire dataset.

  • bounds_low ("auto", "fit", float) – The range for which ticks should be generated.

  • bounds_high ("auto", "fit", float) – The range for which ticks should be generated.

  • interval ("auto", float) – If the value is a positive number, it specifies the length of the tick interval; a negative integer specifies the number of tick intervals; ‘auto’ specifies that the number and length of the tick intervals are automatically calculated, based on the range of the axis.

  • use_endpoints (Boolean) – If True, the lower and upper bounds of the data are used as the lower and upper end points of the axis. If False, the end points might not fall exactly on the bounds.

  • scale ('linear' or 'log') – The type of scale the ticks are for.

Returns

tick_list – Where ticks are to be placed.

Return type

array of floats

Example

If the range of x-values in a line plot span from -15.0 to +15.0, but the plot is currently displaying only the region from 3.1 to 6.83, and the user wants the interval to be automatically computed to be some nice value, then call get_ticks() thusly:

get_ticks(-15.0, 15.0, 3.1, 6.83, "auto")

A reasonable return value in this case would be:

[3.5, 4.0, 4.5, 5.0, 5.5, 6.0, 6.5]
class chaco.ticks.ShowAllTickGenerator

Bases: chaco.ticks.AbstractTickGenerator

Uses the abstract interface, but returns all “positions” instead of decimating the ticks.

You must provide a sequence of values as a positions keyword argument to the constructor.

get_ticks(data_low, data_high, bounds_low, bounds_high, interval, use_endpoints=False, scale='linear')

Returns an array based on positions.

chaco.ticks.auto_bounds(data_low, data_high, tick_interval)

Calculates appropriate upper and lower bounds for the axis from the data bounds and the given axis interval.

The boundaries hit either exactly on the lower and upper values or on the tick mark just beyond the lower and upper values.

chaco.ticks.auto_interval(data_low, data_high, max_ticks=9)

Calculates the tick interval for a range.

The boundaries for the data to be plotted on the axis are:

data_bounds = (data_low,data_high)

The function chooses the number of tick marks, which can be between 3 and max_ticks marks (including end points), and chooses tick intervals at 1, 2, 2.5, 5, 10, 20, …

Returns

interval – tick mark interval for axis

Return type

float

chaco.ticks.auto_ticks(data_low, data_high, bound_low, bound_high, tick_interval, use_endpoints=True)

Finds locations for axis tick marks.

Calculates the locations for tick marks on an axis. The bound_low, bound_high, and tick_interval parameters specify how the axis end points and tick interval are calculated.

Parameters
  • data_low (number) – The minimum and maximum values of the data along this axis. If any of the bound settings are ‘auto’ or ‘fit’, the axis traits are calculated automatically from these values.

  • data_high (number) – The minimum and maximum values of the data along this axis. If any of the bound settings are ‘auto’ or ‘fit’, the axis traits are calculated automatically from these values.

  • bound_low ('auto', 'fit', or a number.) – The lower and upper bounds of the axis. If the value is a number, that value is used for the corresponding end point. If the value is ‘auto’, then the end point is calculated automatically. If the value is ‘fit’, then the axis bound is set to the corresponding data_low or data_high value.

  • bound_high ('auto', 'fit', or a number.) – The lower and upper bounds of the axis. If the value is a number, that value is used for the corresponding end point. If the value is ‘auto’, then the end point is calculated automatically. If the value is ‘fit’, then the axis bound is set to the corresponding data_low or data_high value.

  • tick_interval (can be 'auto' or a number) – If the value is a positive number, it specifies the length of the tick interval; a negative integer specifies the number of tick intervals; ‘auto’ specifies that the number and length of the tick intervals are automatically calculated, based on the range of the axis.

  • use_endpoints (Boolean) – If True, the lower and upper bounds of the data are used as the lower and upper end points of the axis. If False, the end points might not fall exactly on the bounds.

Returns

  • An array of tick mark locations. The first and last tick entries are the

  • axis end points.

chaco.ticks.calc_bound(end_point, tick_interval, is_upper)

Finds an axis end point that includes the value end_point.

If the tick mark interval results in a tick mark hitting directly on the end point, end_point is returned. Otherwise, the location of the tick mark just past end_point is returned. The is_upper parameter specifies whether end_point is at the upper (True) or lower (False) end of the axis.

chaco.ticks.heckbert_interval(data_low, data_high, numticks=8)

Returns a “nice” range and interval for a given data range and a preferred number of ticks. From Paul Heckbert’s algorithm in Graphics Gems.

chaco.ticks.log_auto_ticks(data_low, data_high, bound_low, bound_high, tick_interval, use_endpoints=True)

Like auto_ticks(), but for log scales.

chaco.ticks.tick_intervals(data_low, data_high, intervals)

Computes the best tick interval length to achieve a specified number of tick intervals.

Parameters
  • data_low (number) – The minimum and maximum values of the data along this axis. If any of the bound settings are ‘auto’ or ‘fit’, the axis traits are calculated automatically from these values.

  • data_high (number) – The minimum and maximum values of the data along this axis. If any of the bound settings are ‘auto’ or ‘fit’, the axis traits are calculated automatically from these values.

  • intervals (number) – The desired number of intervals

Returns

Return type

Returns a float indicating the tick interval length.