ridge_scatter_line

ridge_scatter_line

Functions

Name Description
ridge_scatter_line Overlay a precomputed regression line on an existing scatter plot.

ridge_scatter_line

ridge_scatter_line.ridge_scatter_line(
    ax,
    x,
    y_line,
    *,
    line_kwargs=None,
    label=None,
    sort_x=True,
)

Overlay a precomputed regression line on an existing scatter plot.

This function does NOT fit a model. It takes the x-values used in the scatter plot and a matching set of precomputed y-values (for example, predictions returned by get_reg_line), then draws the line on the provided Matplotlib Axes.

Parameters

Name Type Description Default
ax matplotlib.axes.Axes The axes on which to draw the regression line. Typically the same axes returned by ridge_scatter(). required
x array-like of shape (n_samples,) X-coordinates corresponding to the predictions in y_line. required
y_line array-like of shape (n_samples,) Precomputed y-values to plot as a line (e.g., regression predictions). Must be the same length as x. required
line_kwargs dict Keyword arguments forwarded to Matplotlib’s plot() to style the line (e.g., {“linewidth”: 2, “linestyle”: “–”}). If None, defaults are used. None
label str Legend label for the regression line. None
sort_x bool If True (default), sort points by x before plotting so the line does not zig-zag when x is not already ordered. True

Returns

Name Type Description
ax matplotlib.axes.Axes The same axes, with the regression line added.
line matplotlib.lines.Line2D The line artist created by Matplotlib.

Raises

Name Type Description
TypeError If ax is not Axes-like, if line_kwargs is not a dict/None, if label is not a string/None, if sort_x is not boolean, or if inputs cannot be converted to numeric arrays.
ValueError If x or y_line are empty, or if they have different lengths.