ridgeplot._types

Miscellaneous types, type aliases, and related utilities.

ridgeplot._types.CollectionL1

A TypeAlias for a 1-level-deep Collection.

Example

>>> c1 = [1, 2, 3]

alias of Collection[_T]

ridgeplot._types.CollectionL2

A TypeAlias for a 2-level-deep Collection.

Example

>>> c2 = [[1, 2, 3], [4, 5, 6]]

alias of Collection[Collection[_T]]

ridgeplot._types.CollectionL3

A TypeAlias for a 3-level-deep Collection.

Example

>>> c3 = [
...     [[1, 2], [3, 4]],
...     [[5, 6], [7, 8]],
... ]

alias of Collection[Collection[Collection[_T]]]

ridgeplot._types.Float

A TypeAlias for float types.

alias of float | np.floating[Any]

ridgeplot._types.Int

A TypeAlias for a int types.

alias of int | np.integer[Any]

ridgeplot._types.Numeric

A TypeAlias for numeric types.

alias of int | np.integer[Any] | float | np.floating[Any]

class ridgeplot._types.NumericT

A TypeVar variable bound to Numeric types.

alias of TypeVar(‘NumericT’, bound=int | np.integer[Any] | float | np.floating[Any])

ridgeplot._types._is_numeric(obj: int | integer[Any] | float | floating[Any]) Literal[True][source]
ridgeplot._types._is_numeric(obj: Any) bool

Check if the given object is a Numeric type.

ridgeplot._types.XYCoordinate

A 2D \((x, y)\) coordinate, represented as a tuple of two Numeric values.

Example

>>> xy_coord = (1, 2)

alias of Tuple[NumericT, NumericT]

ridgeplot._types.DensityTrace

A 2D line/trace represented as a collection of \((x, y)\) coordinates (i.e. XYCoordinates).

These are equivalent:

  • DensityTrace

  • CollectionL1[XYCoordinate]

  • Collection[Tuple[Numeric, Numeric]]

By convention, the \(x\) values should be non-repeating and increasing. For instance, the following is a valid 2D line trace:

>>> density_trace = [(0, 0), (1, 1), (2, 2), (3, 1), (4, 0)]
../../_images/density_trace.webp

alias of Collection[Tuple[Any, Any]]

ridgeplot._types.DensitiesRow

A DensitiesRow represents a set of DensityTraces that are to be plotted on a given row of a ridgeplot.

These are equivalent:

  • DensitiesRow

  • CollectionL2[XYCoordinate]

  • Collection[Collection[Tuple[Numeric, Numeric]]]

Example

>>> densities_row = [
...     [(0, 0), (1, 1), (2, 0)],                 # Trace 1
...     [(1, 0), (2, 1), (3, 2), (4, 1)],         # Trace 2
...     [(3, 0), (4, 1), (5, 2), (6, 1), (7, 0)], # Trace 3
... ]
../../_images/densities_row.webp

alias of Collection[Collection[Tuple[Any, Any]]]

ridgeplot._types.Densities

The Densities type represents the entire collection of traces that are to be plotted on a ridgeplot.

In a ridgeplot, several traces can be plotted on different rows. Each row is represented by a DensitiesRow object which, in turn, is a collection of DensityTraces. Therefore, the Densities type is a collection of DensitiesRows.

These are equivalent:

  • Densities

  • CollectionL1[DensitiesRow]

  • CollectionL3[XYCoordinate]

  • Collection[Collection[Collection[Tuple[Numeric, Numeric]]]]

Example

>>> densities = [
...     [                                             # Row 1
...         [(0, 0), (1, 1), (2, 0)],                 # Trace 1
...         [(1, 0), (2, 1), (3, 2), (4, 1)],         # Trace 2
...         [(3, 0), (4, 1), (5, 2), (6, 1), (7, 0)], # Trace 3
...     ],
...     [                                             # Row 2
...         [(-2, 0), (-1, 1), (0, 0)],               # Trace 5
...         [(0, 0), (1, 1), (2, 1), (3, 0)],         # Trace 6
...     ],
... ]
../../_images/densities.webp

alias of Collection[Collection[Collection[Tuple[Any, Any]]]]

ridgeplot._types.ShallowDensities

Shallow type for Densities where each row of the ridgeplot contains only a single trace.

These are equivalent:

  • Densities

  • CollectionL1[DensityTrace]

  • CollectionL2[XYCoordinate]

  • Collection[Collection[Tuple[Numeric, Numeric]]]

Example

>>> shallow_densities = [
...     [(0, 0), (1, 1), (2, 0)], # Trace 1
...     [(1, 0), (2, 1), (3, 0)], # Trace 2
...     [(2, 0), (3, 1), (4, 0)], # Trace 3
... ]
../../_images/shallow_densities.webp

alias of Collection[Collection[Tuple[Any, Any]]]

ridgeplot._types.is_shallow_densities(obj: Collection[Collection[Tuple[Any, Any]]]) Literal[True][source]
ridgeplot._types.is_shallow_densities(obj: Any) bool

Check if the given object is a ShallowDensities type.

ridgeplot._types.SamplesTrace

A SamplesTrace is a collection of numeric values representing a set of samples from which a DensityTrace can be estimated via KDE.

Example

>>> samples_trace = [0, 1, 1, 2, 2, 2, 3, 3, 4]
../../_images/samples_trace.webp

alias of Collection[int | np.integer[Any] | float | np.floating[Any]]

ridgeplot._types.SamplesRow

A SamplesRow represents a set of SamplesTraces that are to be plotted on a given row of a ridgeplot.

i.e. a SamplesRow is a collection of SamplesTraces and can be converted into a DensitiesRow by applying KDE to each trace.

Example

>>> samples_row = [
...     [0, 1, 1, 2, 2, 2, 3, 3, 4], # Trace 1
...     [1, 2, 2, 3, 3, 3, 4, 4, 5], # Trace 2
... ]
../../_images/samples_row.webp

alias of Collection[Collection[int | np.integer[Any] | float | np.floating[Any]]]

ridgeplot._types.Samples

The Samples type represents the entire collection of samples that are to be plotted on a ridgeplot.

It is a collection of SamplesRow objects. Each row is represented by a SamplesRow type which, in turn, is a collection of SamplesTraces which can be converted into DensityTrace ‘s by applying a kernel density estimation algorithm.

Therefore, the Samples type can be converted into a Densities type by applying a kernel density estimation (KDE) algorithm to each trace.

See Densities for more details.

Example

>>> samples = [
...     [                                # Row 1
...         [0, 1, 1, 2, 2, 2, 3, 3, 4], # Trace 1
...         [1, 2, 2, 3, 3, 3, 4, 4, 5], # Trace 2
...     ],
...     [                                # Row 2
...         [2, 3, 3, 4, 4, 4, 5, 5, 6], # Trace 3
...         [3, 4, 4, 5, 5, 5, 6, 6, 7], # Trace 4
...     ],
... ]
../../_images/samples.webp

alias of Collection[Collection[Collection[int | np.integer[Any] | float | np.floating[Any]]]]

ridgeplot._types.ShallowSamples

Shallow type for Samples where each row of the ridgeplot contains only a single trace.

Example

>>> shallow_samples = [
...     [0, 1, 1, 2, 2, 2, 3, 3, 4], # Trace 1
...     [1, 2, 2, 3, 3, 3, 4, 4, 5], # Trace 2
... ]
../../_images/shallow_samples.webp

alias of Collection[Collection[int | np.integer[Any] | float | np.floating[Any]]]

ridgeplot._types.is_shallow_samples(obj: Collection[Collection[int | integer[Any] | float | floating[Any]]]) Literal[True][source]
ridgeplot._types.is_shallow_samples(obj: Any) bool

Check if the given object is a ShallowSamples type.

ridgeplot._types.is_flat_str_collection(obj: Collection[str]) Literal[True][source]
ridgeplot._types.is_flat_str_collection(obj: Any) bool

Check if the given object is a CollectionL1[str] type but not a string itself.

ridgeplot._types.nest_shallow_collection(shallow_collection)[source]

Convert a shallow collection type into a deep collection type.

This function should really only be used in the ridgeplot._ridgeplot module to normalize user input.