toyplot.projection module

Classes and functions for projecting coordinates between spaces.

class toyplot.projection.Piecewise(segments)[source]

Bases: toyplot.projection.Projection

Projects between domain and range data using a piecewise collection of linear and log segments.

Parameters:
  • segments (sequence of toyplot.projection.Piecewise.Segment objects, required) – Callers must supply one-to-many segments, each of which defines a mapping between bounded, non-overlapping regions of the domain and range spaces.
  • automethod: (.) – __call__:
class Segment(scale, domain_bounds_min, domain_min, domain_max, domain_bounds_max, range_bounds_min, range_min, range_max, range_bounds_max)[source]

Bases: object

Defines a mapping between bounded regions of domain-space and range-space.

Parameters:
  • scale ("linear" or ("log", base) tuple, required) –
  • domain_bounds_max (domain_bounds_min,) – These values define the bounds of this segment in domain space, and may include positive or negative infinity.
  • domain_max (domain_min,) – These values are mapped to range_min and range_max, respectively.
  • range_max (range_min,) – These values are mapped to domain_min and domain_max, respectively.
  • range_bounds_max (range_bounds_min,) – These values define the bounds of this segment in range space, and may include positive or negative infinity.
inverse(range_values)[source]

Map range values to domain values.

Parameters:
  • range_values (numpy.ndarray or compatible.) –
  • range values to convert. (The) –
Returns:

domain_values – The range values projected into domain values.

Return type:

numpy.ndarray

Examples

>>> projection = toyplot.projection.linear(0, 1, -1, 1)
>>> projection.inverse(-0.5)
0.25
class toyplot.projection.Projection[source]

Bases: object

Abstract interface for objects that can map between one-dimensional domain and range spaces.

__call__(domain_values)[source]

Map domain values to range values.

Parameters:domain_values (numpy.ndarray or compatible.) – The domain values to convert.
Returns:range_values – The domain values projected into range values.
Return type:numpy.ndarray

Examples

>>> projection = toyplot.projection.linear(0, 1, -1, 1)
>>> projection(0.75)
0.5
inverse(range_values)[source]

Map range values to domain values.

Parameters:range_values (numpy.ndarray or compatible.) – The range values to convert.
Returns:domain_values – The range values projected into domain values.
Return type:numpy.ndarray

Examples

>>> projection = toyplot.projection.linear(0, 1, -1, 1)
>>> projection.inverse(-0.5)
0.25
toyplot.projection.linear(domain_min, domain_max, range_min, range_max)[source]

Return an instance of toyplot.projection.Piecewise that performs a linear projection.

Parameters:
  • domain_max (domain_min,) – Defines a closed interval of domain values that will be mapped to the range.
  • range_max (range_min,) – Defines a closed interval of range values that will be mapped to the domain.
Returns:

projection

Return type:

toyplot.projection.Piecewise

toyplot.projection.log(base, domain_min, domain_max, range_min, range_max, linear_domain_min=-1, linear_domain_max=1)[source]

Return an instance of toyplot.projection.Piecewise that performs a log projection.

The returned projection will work correctly with both positive, negative, and zero domain values. To support mapping zero, the projection will switch from log projection to a linear projection within a user-defined region around the origin.

Parameters:
  • base (number) – Logarithmic base used to map from domain values to range values.
  • domain_max (domain_min,) – Defines a closed interval of domain values that will be mapped to the range.
  • range_max (range_min,) – Defines a closed interval of range values that will be mapped to the domain.
  • linear_domain_max (linear_domain_min,) – Defines an interval of domain values around the origin that will be mapped linearly.
Returns:

projection

Return type:

toyplot.projection.Piecewise