chaco.base module

Defines basic traits and functions for the data model.

chaco.base.CubeTrait = ArrayOrNone(shape=(None, None, None))

An 3D array of numbers of shape (Nx, Ny, Nz)

chaco.base.DimensionTrait = Enum("scalar", "point", "image", "cube")

This enumeration lists the fundamental mathematical coordinate types that Chaco supports.

chaco.base.ImageTrait = ArrayOrNone()

An NxM array of numbers or NxMxRGB(A) array of colors.

chaco.base.NumericalSequenceTrait = ArrayOrNone()

A single array of numbers.

chaco.base.PointTrait = ArrayOrNone(shape=(None, 2))

A sequence of pairs of numbers, i.e., an Nx2 array.

chaco.base.SortOrderTrait = Enum("ascending", "descending", "none")

Linear sort order.

chaco.base.arg_find_runs(int_array, order='ascending')

Like find_runs(), but returns a list of tuples indicating the start and end indices of runs in the input int_array.


Find runs where array is True

Performs a binary search of a sorted array for a specified value.

  • values (array) – The values being searched.

  • value (float) – The value being searched for.

  • ascending (-1 or 1) – This value should be 1 if the values array is ascending, or -1 if the values array is descending.


  • Returns the lowest position where the value can be found or where the

  • array value is the last value less (greater) than the desired value.

  • Returns -1 if value is beyond the minimum or maximum of values.

chaco.base.find_runs(int_array, order=<'ascending'|'flat'|'descending'>)list_of_int_arrays

Given an integer array sorted in ascending/descending order or flat order, returns a list of continuous runs of integers inside the list. for example:


returns [ [1,2,3], [6,7,8,9,10,11], [15] ] and:

find_runs([0,0,0,1,1,1,1,0,0,0,0], "flat")

return [ [0,0,0], [1,1,1,1], [0,0,0,0] ]

chaco.base.intersect_range(x, low, high, mask=None)

Discard 1D intervals outside of range, with optional mask

This is an optimized routine for detecting which points are endpoints of visible segments in a 1D polyline. An optional mask can be provided for points which should be excluded from consideration for other reasons (such as not being selected). Returns a mask of points which are endpoints of intervals which potentially intersect the range.

  • x (1d array) – The array of connected interval endpoints. If the x is [x0, x1, x2, …] then the intervals are [[x0, x1], [x1, x2], [x2, x3], …].

  • low (number) – The low end of the range.

  • high (number) – The high end of the range.

  • mask (1d array of bools or None) – The mask of points to consider, or None. If None then any non-finite points will be ignored.


mask – A mask array of points which are endpoints of intervals which potentially intersect the range.

Return type

1d array of bools

chaco.base.left_shift(ary, newval)

Returns a left-shifted version of ary with newval inserted on the right.

chaco.base.n_gon(center, r, nsides, rot_degrees=0)

Generates the points of a regular polygon with specified center, radius, and number of sides.

By default the rightmost point of the polygon is (r,0) but a rotation about the center may be specified with rot_degrees.

chaco.base.point_line_distance(pt, p1, p2)

Returns the perpendicular distance between pt and the line segment between the points p1 and p2.

chaco.base.poly_point(center, r, degrees)
chaco.base.reverse_map_1d(data, pt, sort_order, floor_only=False)

Returns the index of pt in the array data.

Raises IndexError if pt is outside the range of values in data.

  • data (1-D array) – data to search

  • pt (scalar value) – value to find, which must be within the value range of data

  • sort_order (string) – “ascending” or “descending”

  • floor_only (bool) – if true, don’t find “nearest” point, instead find last point less (greater) than pt

chaco.base.right_shift(ary, newval)

Returns a right-shifted version of ary with newval inserted on the left.

chaco.base.sort_points(array_of_points, index=<0|1>)sorted_array

Takes a list of points as an Nx2 array and sorts them according to their x- or y-coordinate. If index is zero, the points are sorted on their x-coordinate.