ridge#

API pages include interactive (HTML) plots that would possibly not render correctly on a mobile device.

ridge(data: AnnData, key: str, group_by: str, *, frame: DataFrame | None = None, scale: float = 2.0, mapping: FeatureSpec | None = None, axis: Literal[0, 1] | None = None, threshold: float | None = None, add_keys: Sequence[str] | str | None = None, groups: Sequence[str] | str | None = None, drop: Sequence[str] | str | None = None, tooltips: Literal['none'] | Sequence[str] | FeatureSpec | None = None, observations_name: str = 'Barcode', variables_name: str = 'Variable', interactive: bool = False, **geom_kwargs) PlotSpec#

Ridge Plot.

Parameters:
  • data (AnnData) – The AnnData object of the single cell data.

  • key (str) – The key to get the values (numerical). e.g., ‘total_counts’ or a gene name.

  • group_by (str) – The key to group the ridges by (categorical). e.g., ‘cell_type’ or ‘leiden’.

  • frame (DataFrame | None, default None) – A prebuilt frame to plot from. If provided, the frame is used directly and building from data is skipped. Must contain the key and group_by columns.

  • scale (float, default 2.0) – Scaling factor for the height of the ridges.

  • mapping (FeatureSpec | None, default None) – Additional aesthetic mappings for the plot, the result of aes().

  • axis ({0,1} | None, default None) – axis of the data, 0 for observations and 1 for variables.

  • threshold (float | None, default None) – If provided, filters out rows where the value column is below the threshold.

  • add_keys (Sequence[str] | str | None, default None) – Additional keys to include in the dataframe.

  • groups (str | Sequence[str] | None, default None) – Show only specific groups, keeping rows where group_by matches any of them. Categorical grouping columns only.

  • drop (str | Sequence[str] | None, default None) – Drop specific groups, filtering out rows where group_by matches any of them. Categorical grouping columns only.

  • tooltips ({'none'} | Sequence[str] | FeatureSpec | None, default None) – Tooltips to show when hovering over the geom. Accepts Sequence[str] or result of layer_tooltips() for more complex tooltips. Use ‘none’ to disable tooltips.

  • observations_name (str, default 'Barcode') – The name to give to barcode (or index) column in the dataframe.

  • variables_name (str, default 'Variable') – The name to give to variable index column in the dataframe.

  • interactive (bool, default False) – Whether to make the plot interactive.

  • **geom_kwargs – Additional parameters for the geom_area_ridges layer. For more information on geom_area_ridges parameters, see: https://lets-plot.org/python/pages/api/lets_plot.geom_area_ridges.html

Returns:

PlotSpec – Ridge plot.

Raises:

UnsupportedDataTypeError – If data is not a supported single-cell data object.

Examples

import cellestial as cl
import scanpy as sc

from lets_plot import *

data = cl.datasets.pbmc3k(cache_directory="data")

ridge = (
    cl.ridge(
        data,
        key="B2M",
        group_by="cell_type_lvl1",
    )
)

ridge

Customize the geom.

ridge = (
    cl.ridge(
        data,
        key="B2M",
        group_by="cell_type_lvl1",
        alpha=0.7,
        color="#1f1f1f",
    )
)

ridge