Pies

detroit.pie()

The pie generator computes the necessary angles to represent a tabular dataset as a pie or donut chart; these angles can then be passed to an arc generator. (The pie generator does not produce a shape directly.)

class detroit.shape.pie.Pie

The pie generator computes the necessary angles to represent a tabular dataset as a pie or donut chart; these angles can then be passed to an arc generator. (The pie generator does not produce a shape directly.)

__call__(data: Iterable[T], *args) list[dict]

Generates a pie for the given array of data, returning an array of objects representing each datum’s arc angles.

Parameters:
  • data (Iterable[T]) – Data input

  • args (Any) – Additional arguments propagated to the pie’s accessor functions

Returns:

List of arcs

Return type:

list[dict]

Examples

For example, given a set of numbers, here is how to compute the angles for a pie chart:

>>> data = [1, 1, 2, 3, 5, 8, 13, 21]
>>> pie = d3.pie()
>>> pie(data)

Each object in the returned array has the following properties:

  • data - the input datum; the corresponding element in the input data array.

  • value - the numeric value of the arc.

  • index - the zero-based sorted index of the arc.

  • start_angle - the start angle of the arc.

  • end_angle - the end angle of the arc.

  • pad_angle - the pad angle of the arc.

set_value(value: Callable[[T], float] | Callable[[T, int], float] | Callable[[T, int, list[Element]], float] | int | float) Pie

If value is specified, sets the value accessor to the specified function or number and returns this pie generator.

Parameters:

value (Accessor[T, float] | Number) – Number or accessor function

Returns:

Itself

Return type:

Pie

set_sort_values(sort_values: Callable[[float], float]) Pie

If sort_values is specified, sets the value comparator to the specified function and returns this pie generator.

Parameters:

sort_values (Callable[[float], float]) – Value input

Returns:

Itself

Return type:

Pie

set_sort(sort: Callable[[float], float]) Pie

If sort is specified, sets the data comparator to the specified function and returns this pie generator.

Parameters:

sort (Callable[[float], float]) – Sort function

Returns:

Itself

Return type:

Pie

set_start_angle(start_angle: Callable[[...], float] | int | float) Pie

If start_angle is specified, sets the overall start angle of the pie to the specified function or number and returns this pie generator.

Parameters:

start_value (Callable[[..., float]] | Number) – Start angle input

Returns:

Itself

Return type:

Pie

set_end_angle(end_angle: Callable[[...], float] | int | float) Pie

If end_angle is specified, sets the overall end angle of the pie to the specified function or number and returns this pie generator.

Parameters:

end_angle (Callable[..., float] | Number) – End angle input

Returns:

Itself

Return type:

Pie

set_pad_angle(pad_angle: Callable[[...], float] | int | float) Pie

If pad_angle is specified, sets the pad angle to the specified function or number and returns this pie generator.

Parameters:

pad_angle (Callable[..., float] | Number) – Pad angle input

Returns:

Itself

Return type:

Pie