Band scales

detroit.scale_band() ScaleBand
detroit.scale_band(range_vals: list[int | float]) ScaleBand
detroit.scale_band(domain: list[T], range_vals: list[int | float]) ScaleBand

Builds a new band scale with the specified domain and range, no padding, no rounding and center alignment

Parameters:
  • domain (list[T]) – Array of values

  • range_vals (list[Number]) – Array of numbers

Returns:

Scale object

Return type:

ScaleBand

Examples

>>> scale = d3.scale_band(["a", "b", "c"], [0, 960])
>>> for c in "abcdefgh":
...     print(c, scale(c))
...
...
a 0.0
b 320.0
c 640.0
d None
e None
f None
g None
h None
>>> scale.get_bandwidth()
320.0
detroit.scale_point() ScaleBand[T]
detroit.scale_point(range_vals: list[int | float]) ScaleBand[T]
detroit.scale_point(domain: list[T], range_vals: list[int | float]) ScaleBand[T]

Builds a new point scale with the specified domain and range, no padding, no rounding and center alignment

Parameters:
  • domain (list[T]) – Array of values

  • range_vals (list[Number]) – Array of numbers

Returns:

Scale object

Return type:

ScaleBand

Examples

>>> scale = d3.scale_point(["a", "b", "c"], [0, 960])
>>> for c in "abcdefgh":
...     print(c, scale(c))
...
...
a 0.0
b 480.0
c 960.0
d None
e None
f None
g None
h None
>>> scale.get_bandwidth()
0.0
class detroit.scale.band.ScaleBand

Band scales are like band scales except the output range is continuous and numeric. The scale divides the continuous range into uniform bands. Band scales are typically used for bar charts with an band or categorical dimension.

__call__(d: T) int | float

Given a value from the domain, returns the corresponding value from the range.

Parameters:

d (T) – Input value

Returns:

Corresponding value from the range

Return type:

Number

set_domain(domain: list[T]) ScaleBand

Sets the scale’s domain to the specified array of values

Parameters:

domain (list[T]) – Domain

Returns:

Itself

Return type:

ScaleBand

set_range(range_vals: list[int | float]) ScaleBand

Sets the scale’s range to the specified array of numbers

Parameters:

range_vals (list[Number]) – Range

Returns:

Itself

Return type:

ScaleBand

set_unknown(unknown: Any) ScaleOrdinal

Sets the output value of the scale for undefined or NaN input values.

Parameters:

unknown (Any) – Unknown value

Returns:

Itself

Return type:

ScaleOrdinal

set_round(round_val: bool) ScaleBand

Enable or disable rounding accordingly

Parameters:

round_val (bool) – Round value

Returns:

Itself

Return type:

ScaleBand

set_align(align: int | float) ScaleBand

Sets the alignment to the specified value which must be in the range [0, 1]

Parameters:

align (Number) – Alignment value

Returns:

Itself

Return type:

ScaleBand

set_padding(padding: int | float) ScaleBand

A convenience method for setting the inner and outer padding to the same padding value.

Parameters:

padding (Number) – Padding value

Returns:

Itself

Return type:

ScaleBand

set_padding_inner(padding_inner: int | float) ScaleBand

Sets the inner padding to the specified number which must be less than or equal to 1

Parameters:

padding_inner (Number) – Inner padding value

Returns:

Itself

Return type:

ScaleBand

set_padding_outer(padding_outer: int | float) ScaleBand

Sets the outer padding to the specified number which is typically in the range [0, 1]

Parameters:

padding_outer (Number) – Outer padding value

Returns:

Itself

Return type:

ScaleBand