dotplot#

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

dotplot(data: AnnData, keys: Sequence[str] | Mapping[str, Sequence[str]] | None = None, group_by: str | None = None, *, markers: bool | str = False, n_genes: int = 5, groups: Sequence[str] | None = None, mapping: FeatureSpec | None = None, threshold: float = 0, size_scale: float = 1.0, variable_column: str = 'variable', color_low: str = '#e6e6e6', color_mid: str | None = None, color_high: str = '#D2042D', mid_point: Literal['mean', 'median', 'mid'] | float = 'mid', sort_by: str | Sequence[str] | None = None, sort_order: Literal['ascending', 'descending'] = 'descending', percentage_key: str = 'pct_exp', mean_key: str = 'avg_exp', rectangle: bool = True, dendrogram: bool = False, dendrogram_color: str = 'black', dendrogram_size: float = 0.5, dendrogram_key: str | None = None, dendrogram_kwargs: dict | None = None, rectangle_size: float = 0.8, rectangle_color: str = '#3f3f3f', rectangle_kwargs: dict | None = None, key_labels: bool = True, key_labels_text_size: float = 1.0, key_labels_bracket_size: float = 0.6, key_labels_text_color: str = 'black', key_labels_bracket_color: str = 'black', key_labels_width: float = 0.6, tooltips: Literal['none'] | Sequence[str] | FeatureSpec | None = None, interactive: bool = False, **geom_kwargs) PlotSpec#

Dotplot.

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

  • keys (Sequence[str] | Mapping[str, Sequence[str]] | None, default None) – Variable keys to include, placed on the x-axis. A mapping assigns keys to group labels (no key in more than one group). Must be None when markers is set.

  • group_by (str | None, default None) – The key to group the data by. Inferred from a precomputed ranking when markers is set.

  • markers (bool | str, default False) – Derive keys from a precomputed ranking. Pass True to use the default ranking key, or a string to read a custom key (e.g. “rank_genes_groups_wilcoxon”).

  • n_genes (int, default 5) – Number of top genes to take per group when markers is set.

  • groups (Sequence[str] | None, default None) – Subset of groups to include when markers is set; None keeps all groups in their stored order.

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

  • threshold (float, default 0) – The expression threshold to consider a gene as expressed.

  • size_scale (float, default 1.0) – Scaling factor for the point sizes in the plot.

  • point_size (float, default 1.0) – Scaling factor for the point sizes in the plot.

  • variable_column (str, default 'variable') – Name for the variable column after unpivoting.

  • color_low (str, default '#e6e6e6') – Color for low values in the gradient.

  • color_mid (str | None, default None) – Color for mid values in the gradient.

  • color_high (str, default '#D2042D') – Color for high values in the gradient.

  • mid_point ({'mean', 'median', 'mid'} | float, default 'mid') – Midpoint for the color gradient.

  • fill (bool, optional) – Whether to use fill aesthetic instead of color, by default False.

  • sort_by (str | None) – The column to sort the results by, by default None.

  • sort_order (str, default 'descending') – The sort order, either ‘ascending’ or ‘descending’.

  • percentage_key (str, default 'pct_exp') – The name of the percentage column.

  • mean_key (str, default 'avg_exp') – The name of the mean expression column.

  • rectangle (bool, default True) – Whether to add a rectangle border around the data area

  • dendrogram (bool, default False) – Whether to add a dendrogram for the group_by axis. Uses scanpy.tl.dendrogram if not already computed. When True, group order is determined by the dendrogram.

  • dendrogram_color (str, default 'black') – Color of the dendrogram segments.

  • dendrogram_size (float, default 0.5) – Size (thickness) of the dendrogram segments.

  • dendrogram_key (str | None, default None) – Specific key holding the precomputed dendrogram. By default, dendrogram_{group_by} is used.

  • dendrogram_kwargs (dict | None, default None) – Additional parameters to pass to the dendrogram geom_segment.

  • rectangle_size (float, default 0.8) – Size (thickness) of the rectangle border.

  • rectangle_color (str, default '#3f3f3f') – Color of the rectangle border.

  • rectangle_kwargs (dict | None, default None) – Additional parameters to pass to the rectangle geom_rect.

  • key_labels (bool, default True) – Whether to draw bracket labels above the plot when keys is a mapping.

  • key_labels_text_size (float, default 1.0) – Scale multiplier on the auto-computed bracket label text size.

  • key_labels_bracket_size (float, default 0.6) – Size (thickness) of the bracket lines.

  • key_labels_text_color (str, default 'black') – Color of the bracket label text.

  • key_labels_bracket_color (str, default 'black') – Color of the bracket lines.

  • key_labels_width (float, default 0.6) – Bracket width (in column units) for a singleton group. Multi-key groups extend key_labels_width / 2 past the first and last key on each side.

  • 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.

  • show_tooltips (bool, default True) – Whether to show tooltips.

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

  • **geom_kwargs (Any) – Additional keyword arguments for the geom_point layer.

Returns:

PlotSpec – Dotplot.

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

  • KeyNotFoundError – If markers is enabled and the requested ranking result or group is missing.

  • DuplicateKeysError – If a mapping passed to keys assigns the same key to multiple groups.

  • ValueError – If keys and group_by are missing while markers is disabled.

Examples

A simple dotplot.

import scanpy as sc
from lets_plot import *

import cellestial as cl

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

markers = ["C1QA", "PSAP", "CD79A", "CD79B", "CST3", "LYZ"]

dot = cl.dotplot(
    data,
    keys=markers,
    group_by="cell_type_lvl1",
)
dot

Dotplot allows dendrograms among the groups.

dot = cl.dotplot(
    data,
    keys=markers,
    group_by="cell_type_lvl1",
    dendrogram=True,
)
dot

Modify the dendrogram and rectangle borders.

dot = cl.dotplot(
    data,
    keys=markers,
    group_by="cell_type_lvl1",
    dendrogram=True,
    dendrogram_color="gray",
    dendrogram_size=1,
    rectangle_color="gray",
    rectangle_size=3,
)
dot

Plot the top genes from a precomputed ranking:

sc.tl.rank_genes_groups(data, groupby="cell_type_lvl1")
cl.dotplot(data, markers=True, n_genes=5)
WARNING: It seems you use rank_genes_groups on the raw count data. Please logarithmize your data before calling rank_genes_groups.