RidgelinePlot
One density ridge per group, stacked and partly overlapping. The Ridgeline Plot guide shows every feature on real data; this page is the contract: the function, the shape of its data, the keys style takes, and the constant each parameter accepts.
Function
datachart.charts.RidgelinePlot
RidgelinePlot(
data: (
list[RidgelineDataPointAttrs]
| list[list[RidgelineDataPointAttrs]]
),
*,
title: str | None = None,
xlabel: str | None = None,
ylabel: str | None = None,
subtitle: str | list[str | None] | None = None,
emphasis: (
EMPHASIS | str | list[str | None] | None
) = None,
emphasis_rule: EmphasisRuleAttrs | None = None,
figsize: FIG_SIZE | tuple[float, float] | None = None,
xmin: int | float | None = None,
xmax: int | float | None = None,
ymin: int | float | None = None,
ymax: int | float | None = None,
show_legend: bool | None = None,
legend: LegendSettingAttrs | None = None,
show_grid: SHOW_GRID | str | bool | None = None,
aspect_ratio: ASPECT_RATIO | str | None = None,
orientation: (
ORIENTATION | str | None
) = ORIENTATION.HORIZONTAL,
scaley: SCALE | str | None = None,
subplots: bool | None = None,
max_cols: int | None = None,
sharex: bool | None = None,
sharey: bool | None = None,
style: (
RidgelineStyleAttrs
| list[RidgelineStyleAttrs | None]
| None
) = None,
xticks: (
list[int | float] | list[list[int | float]] | None
) = None,
xticklabels: list[str] | list[list[str]] | None = None,
xtickrotate: int | list[int | None] | None = None,
yticks: (
list[int | float] | list[list[int | float]] | None
) = None,
yticklabels: list[str] | list[list[str]] | None = None,
ytickrotate: int | list[int | None] | None = None,
xticks_format: (
VALUE_FORMAT | DATE_FORMAT | str | None
) = None,
yticks_format: (
VALUE_FORMAT | DATE_FORMAT | str | None
) = None,
vlines: (
VLineSettingAttrs
| list[VLineSettingAttrs]
| list[
VLineSettingAttrs
| list[VLineSettingAttrs]
| None
]
| None
) = None,
hlines: (
HLineSettingAttrs
| list[HLineSettingAttrs]
| list[
HLineSettingAttrs
| list[HLineSettingAttrs]
| None
]
| None
) = None,
vspans: (
VSpanSettingAttrs
| list[VSpanSettingAttrs]
| list[
VSpanSettingAttrs
| list[VSpanSettingAttrs]
| None
]
| None
) = None,
hspans: (
HSpanSettingAttrs
| list[HSpanSettingAttrs]
| list[
HSpanSettingAttrs
| list[HSpanSettingAttrs]
| None
]
| None
) = None,
texts: (
TextSettingAttrs
| list[TextSettingAttrs]
| list[
TextSettingAttrs | list[TextSettingAttrs] | None
]
| None
) = None,
label: str | list[str | None] | None = None,
value: str | list[str | None] | None = None,
bandwidth: BANDWIDTH | str | float | None = None,
overlap: float | None = None,
normalize: (
RIDGELINE_SCALE | str | None
) = RIDGELINE_SCALE.PER_ROW,
inner: VIOLIN_INNER | str | None = None,
fill: bool = True,
show_outline: bool = True,
sort: SORT | str | None = SORT.NONE
) -> plt.Figure
Creates the ridgeline plot.
A ridgeline plot (joy plot) draws the kernel density estimate of each group's numeric distribution as a ridge on its own row, the rows stacked and partly overlapping, first row at the top. Use it to show how one distribution shifts across many groups in the space a grid of histograms would spend on a few.
Examples:
>>> from datachart.charts import RidgelinePlot
>>> figure = RidgelinePlot(
... data=[
... {"label": "Group A", "value": 10},
... {"label": "Group A", "value": 15},
... {"label": "Group A", "value": 12},
... {"label": "Group B", "value": 20},
... {"label": "Group B", "value": 25},
... {"label": "Group B", "value": 22},
... ],
... title="Basic Ridgeline Plot",
... xlabel="Value",
... ylabel="Group"
... )
| PARAMETER | DESCRIPTION |
|---|---|
data
|
The data points for the ridgeline plot(s). Can be a single list of data points
for one chart, or a list of lists for multiple charts/subplots.
Each data point should have a
TYPE:
|
title
|
The title of the chart.
TYPE:
|
xlabel
|
The x-axis label.
TYPE:
|
ylabel
|
The y-axis label.
TYPE:
|
subtitle
|
The subtitle(s) for individual charts (subplots).
TYPE:
|
emphasis
|
The emphasis role(s), aligned with the ridge labels of one call in input order (a single value applies to every ridge): "background" mutes a ridge and its inner marks, "highlight" bolds its outline, None leaves it unchanged.
TYPE:
|
emphasis_rule
|
A rule that highlights the groups matching it and mutes the rest:
TYPE:
|
figsize
|
The size of the figure.
TYPE:
|
xmin
|
The minimum x-axis value; on the value axis it also bounds the density grid.
TYPE:
|
xmax
|
The maximum x-axis value; on the value axis it also bounds the density grid.
TYPE:
|
ymin
|
The minimum y-axis value; bounds the grid when vertical.
TYPE:
|
ymax
|
The maximum y-axis value; bounds the grid when vertical.
TYPE:
|
show_legend
|
Whether to show the legend; the ridges add no entries, their labels sit on the category axis.
TYPE:
|
legend
|
The per-figure legend setting: title, location, column count
and alignment; each field falls back to the theme. See
TYPE:
|
show_grid
|
Which grid lines to show (e.g., "both", "x", "y");
TYPE:
|
aspect_ratio
|
The aspect ratio of the axes ("auto" or "equal"). See
TYPE:
|
orientation
|
"horizontal" (default) runs the value axis along x and
stacks the rows along y, first row at the top; "vertical" runs
the rows along x, first row at the left, each ridge rising
rightward from its tick.
See
TYPE:
|
scaley
|
The value-axis scale (e.g., "log", "linear").
TYPE:
|
subplots
|
Whether to create separate subplots for each chart.
TYPE:
|
max_cols
|
Maximum number of columns in subplots (when subplots=True).
TYPE:
|
sharex
|
Whether to share the x-axis in subplots.
TYPE:
|
sharey
|
Whether to share the y-axis in subplots.
TYPE:
|
style
|
Style configuration(s) for the ridges.
TYPE:
|
xticks
|
Custom x-axis tick positions.
TYPE:
|
xticklabels
|
Custom x-axis tick labels.
TYPE:
|
xtickrotate
|
Rotation angle for x-axis tick labels.
TYPE:
|
yticks
|
Custom y-axis tick positions.
TYPE:
|
yticklabels
|
Custom y-axis tick labels.
TYPE:
|
ytickrotate
|
Rotation angle for y-axis tick labels.
TYPE:
|
xticks_format
|
The x-axis tick label format: a
TYPE:
|
yticks_format
|
The y-axis tick label format, as
TYPE:
|
vlines
|
Vertical line(s) to plot.
TYPE:
|
hlines
|
Horizontal line(s) to plot.
TYPE:
|
vspans
|
Vertical reference band(s) to shade, between two x positions.
TYPE:
|
hspans
|
Horizontal reference band(s) to shade, between two y positions.
TYPE:
|
texts
|
Text annotation(s) to draw.
TYPE:
|
label
|
The key name in data for label/category values (default: "label").
TYPE:
|
value
|
The key name in data for numeric values (default: "value").
TYPE:
|
bandwidth
|
The KDE bandwidth: None or "scott" (Scott's rule), "silverman", or a
scalar factor. See
TYPE:
|
overlap
|
How far a ridge's peak rises into the row above, in
TYPE:
|
normalize
|
"per_row" scales every ridge to the same peak so shapes
compare; "common" keeps one density scale so heights compare. See
TYPE:
|
inner
|
The marks drawn inside each ridge, up to its height: "median" (one line),
"quartiles" (dashed median, dotted Q1/Q3), or None. See
TYPE:
|
fill
|
Whether to fill each ridge.
TYPE:
|
show_outline
|
Whether to stroke each ridge's density curve.
TYPE:
|
sort
|
The row order: None keeps input order, "ascending" or
"descending" orders the rows by their median; ties keep input
order. See |
| RETURNS | DESCRIPTION |
|---|---|
plt.Figure
|
The figure containing the ridgeline plot. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If |
Data
Each record in data is a RidgelineDataPointAttrs; the label and value parameters rename its keys.
datachart.typings.RidgelineDataPointAttrs
Bases: TypedDict
The data point attributes for the ridgeline plot.
| ATTRIBUTE | DESCRIPTION |
|---|---|
label |
The category label; one ridge per label.
TYPE:
|
value |
The numeric value.
TYPE:
|
Style
style takes the keys of RidgelineStyleAttrs. The chart also reads the shared groups it draws: reference lines (VLineStyleAttrs and HLineStyleAttrs), reference bands (VSpanStyleAttrs and HSpanStyleAttrs) and text annotations (TextStyleAttrs). Every key falls back to the theme, so the same keys set the default look through config.
datachart.typings.RidgelineStyleAttrs
Bases: TypedDict
The typing for the ridgeline plot style.
| ATTRIBUTE | DESCRIPTION |
|---|---|
plot_ridgeline_color |
The ridge fill color; defaults to the palette color.
TYPE:
|
plot_ridgeline_alpha |
The alpha value of the ridge fill.
TYPE:
|
plot_ridgeline_linewidth |
The line width of the ridge outline.
TYPE:
|
plot_ridgeline_edgecolor |
The color of the ridge outline; defaults to the fill.
TYPE:
|
plot_ridgeline_overlap |
How far a peak rises into the row above, in
TYPE:
|
plot_ridgeline_inner_color |
The color of the inner marks; defaults to the font color.
TYPE:
|
plot_ridgeline_inner_linewidth |
The line width of the inner marks.
TYPE:
|
plot_ridgeline_hatch |
The hatch pattern of the ridge fill.
TYPE:
|
Constants
The parameters that accept a constant, with the class in datachart.constants that lists its values.
| Parameter | Constant |
|---|---|
normalize |
RIDGELINE_SCALE |
emphasis |
EMPHASIS |
figsize |
FIG_SIZE |
legend={"location": ..., "alignment": ...} |
LEGEND_LOCATION, LEGEND_ALIGN |
show_grid |
SHOW_GRID |
aspect_ratio |
ASPECT_RATIO |
orientation |
ORIENTATION |
scaley |
SCALE |
xticks_format |
VALUE_FORMAT, DATE_FORMAT |
yticks_format |
VALUE_FORMAT, DATE_FORMAT |
bandwidth |
BANDWIDTH |
inner |
VIOLIN_INNER |
sort |
SORT |