ondata_legend#

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

ondata_legend(*, plot: PlotSpec | None = None, x: str | None = None, y: str | None = None, group_by: str | None = None, size: float = 12, color: str = '#3f3f3f', fontface: str = 'bold', family: str = 'sans', alpha: float = 1, label: bool = False, repel: bool = False, **geom_kwargs) DeferredLayer#

Layer of geom_text that places per-group labels at median coordinates.

Parameters:
  • plot (PlotSpec | None, default None) – If provided, labels are computed from this plot’s data and aesthetics regardless of which plot the resulting layer is added to. When None, the layer is deferred and introspects the plot it is added to via +.

  • x (str | None, default None) – The column name in the data used for x-axis coordinates. e.g ‘X_UMAP1’. If None, it will be inferred from the plot aesthetics.

  • y (str | None, default None) – The column name in the data used for y-axis coordinates. e.g ‘X_UMAP2’. If None, it will be inferred from the plot aesthetics.

  • group_by (str | None, default None) – The column name in the data used to group clusters by. e.g ‘cell_type’. If None, it will be inferred from the plot’s color aesthetic.

  • size (float, default 12) – Size of the legend text.

  • color (str, default '#3f3f3f') – Color of the legend text.

  • fontface (str, default 'bold') – Fontface of the legend text. https://lets-plot.org/python/pages/aesthetics.html#font-face

  • family (str, default 'sans') – Font family of the legend text. https://lets-plot.org/python/pages/aesthetics.html#font-family

  • alpha (float, default 1) – Alpha (transparency) of the legend text.

  • label (bool, default False) – If True, draw labels with a filled background using geom_label.

  • repel (bool, default False) – If True, use geom_text_repel so labels are shifted to avoid overlapping each other. Repel-specific options (e.g. box_padding, point_padding, max_iter, seed) can be passed via geom_kwargs.

  • **geom_kwargs – Additional parameters for the underlying geom layer. For geom_text parameters, see: https://lets-plot.org/python/pages/api/lets_plot.geom_text.html For geom_label parameters (when label=True), see: https://lets-plot.org/python/pages/api/lets_plot.geom_label.html For geom_text_repel parameters (when repel=True), see: https://lets-plot.org/python/pages/api/lets_plot.geom_text_repel.html For geom_label_repel parameters (when label=True and repel=True), see: https://lets-plot.org/python/pages/api/lets_plot.geom_label_repel.html

Returns:

DeferredLayer – On-data legend layer.

Raises:

MissingAestheticError – If x, y, or group_by cannot be provided explicitly or inferred from the receiving plot.

Examples

A UMAP plot without on-data legends.

import cellestial as cl
import scanpy as sc

from lets_plot import *

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

umap = cl.umap(data, key="cell_type_lvl1", axis_type="arrow", size=1.5)
umap

Add the on-data legend.

umap + cl.ondata_legend()

Modify as needed.

umap + cl.ondata_legend(size=10, family="mono", fontface="italic")