ridgeplot._figure_factory

Ridgeline plot figure factory logic.

ridgeplot._figure_factory.LabelsArray

A LabelsArray represents the labels of traces in a ridgeplot.

Example

>>> labels_array: LabelsArray = [
...     ["trace 1", "trace 2", "trace 3"],
...     ["trace 4", "trace 5"],
... ]

alias of Collection[Collection[str]]

ridgeplot._figure_factory.ShallowLabelsArray

Shallow type for LabelsArray.

Example

>>> labels_array: ShallowLabelsArray = ["trace 1", "trace 2", "trace 3"]

alias of Collection[str]

ridgeplot._figure_factory.ColorsArray

A ColorsArray represents the colors of traces in a ridgeplot.

Example

>>> colors_array: ColorsArray = [
...     ["red", "blue", "green"],
...     ["orange", "purple"],
... ]

alias of Collection[Collection[str]]

ridgeplot._figure_factory.ShallowColorsArray

Shallow type for ColorsArray.

Example

>>> colors_array: ShallowColorsArray = ["red", "blue", "green"]

alias of Collection[str]

ridgeplot._figure_factory.MidpointsArray

A MidpointsArray represents the midpoints of colorscales in a ridgeplot.

Example

>>> midpoints_array: MidpointsArray = [
...     [0.2, 0.5, 1],
...     [0.3, 0.7],
... ]

alias of Collection[Collection[float]]

ridgeplot._figure_factory.Colormode

The ridgeplot.ridgeplot.colormode argument in ridgeplot.ridgeplot().

alias of Literal[‘row-index’, ‘trace-index’, ‘mean-minmax’, ‘mean-means’]

ridgeplot._figure_factory._D3HF = '.7'

Default (d3-format) format for floats in hover labels.

After trying to read through the plotly.py source code, I couldn’t find a simple way to replicate the default hover format using the d3-format syntax in Plotly’s ‘hovertemplate’ parameter. The closest I got was by using the string below, but it’s not quite the same… (see ‘.7~r’ as well)

ridgeplot._figure_factory._DEFAULT_HOVERTEMPLATE = '(%{x:.7}, %{customdata[0]:.7})<br><extra>%{fullData.name}</extra>'

Default hovertemplate for density traces.

See ridgeplot._figure_factory.RidgePlotFigureFactory.draw_density_trace().

ridgeplot._figure_factory.get_xy_extrema(densities)[source]

Get the global x-y extrema (x_min, x_max, y_min, y_max) over all DensityTraces in the Densities array.

Parameters:

densities – A Densities array.

Returns:

A tuple of the form (x_min, x_max, y_min, y_max).

Return type:

Tuple[Numeric, Numeric, Numeric, Numeric]

Examples

>>> get_xy_extrema(
...     [
...         [
...             [(0, 0), (1, 1), (2, 2), (3, 3)],
...             [(0, 0), (1, 1), (2, 2)],
...             [(0, 0), (1, 1), (2, 2), (3, 3), (4, 4)],
...         ],
...         [
...             [(-2, 2), (-1, 1), (0, 1)],
...             [(2, 2), (3, 1), (4, 1)],
...         ],
...     ]
... )
(-2, 4, 0, 4)
ridgeplot._figure_factory._mul(a, b)[source]

Multiply two tuples element-wise.

class ridgeplot._figure_factory.RidgePlotFigureFactory(densities, colorscale, coloralpha, colormode, labels, linewidth, spacing, show_yticklabels, xpad)[source]

Bases: object

Refer to ridgeplot.ridgeplot().

property colormode_maps: dict[str, Callable[[], MidpointsArray]]
draw_base(x, y_shifted)[source]

Draw the base for a density trace.

Adds an invisible trace at constant y that will serve as the fill-limit for the corresponding density trace.

draw_density_trace(x, y, y_shifted, label, color)[source]

Draw a density trace.

Adds a density ‘trace’ to the Figure. The fill="tonexty" option fills the trace until the previously drawn trace (see draw_base()). This is why the base trace must be drawn first.

update_layout(y_ticks)[source]

Update figure’s layout.

_compute_midpoints_row_index()[source]

colormode=’row-index’

Uses the row’s index. e.g. if the ridgeplot has 3 rows of traces, then the midpoints will be [[1, …], [0.5, …], [0, …]].

_compute_midpoints_trace_index()[source]

colormode=’trace-index’

Uses the trace’s index. e.g. if the ridgeplot has a total of 3 traces (across all rows), then the midpoints will be 0, 0.5, and 1, respectively.

_compute_midpoints_mean_minmax()[source]

colormode=’mean-minmax’

Uses the min-max normalized (weighted) mean of each density to calculate the midpoints. The normalization min and max values are the minimum and maximum x-values from all densities, respectively.

_compute_midpoints_mean_means()[source]

colormode=’mean-means’

Uses the min-max normalized (weighted) mean of each density to calculate the midpoints. The normalization min and max values are the minimum and maximum mean values from all densities, respectively.

pre_compute_colors()[source]
make_figure()[source]