histograms#

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

histograms(data: AnnData, keys: Sequence[str], *, group_by: str | None = None, groups: Sequence[str] | str | None = None, drop: Sequence[str] | str | None = None, mapping: FeatureSpec | None = None, axis: Literal[0, 1] | None = None, color: str | None = None, fill: str | None = None, bins: int | None = None, binwidth: float | None = None, add_keys: Sequence[str] | str | None = None, tooltips: Literal['none'] | Sequence[str] | FeatureSpec | None = None, geom_fill: str | None = None, geom_color: str | None = None, observations_name: str = 'Barcode', variables_name: str = 'Variable', interactive: bool = False, value_column: str = 'value', variable_column: str = 'variable', share_axis: bool = False, share_ticks: bool = False, layers: Sequence[FeatureSpec | LayerSpec] | FeatureSpec | LayerSpec | None = None, ncol: int | None = None, sharex: str | None = None, sharey: str | None = None, widths: list[float] | None = None, heights: list[float] | None = None, hspace: float | None = None, vspace: float | None = None, fit: bool | None = None, align: bool | None = None, guides: str = 'auto', **geom_kwargs) SupPlotsSpec#

Histograms.

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

  • keys (list[str] | tuple[str] | Sequence[str]) – The keys to get the values (numerical). e.g., [‘total_counts’, ‘pct_counts_in_top_50_genes’] or a list of gene names.

  • group_by (str | None, default None) – Column to filter observations on. Only rows with a non-null value are kept.

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

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

  • color (str | None, default None) – Color aesthetic to split the histogram (categorical). Shortcut for mapping=aes(color=…) e,g., ‘cell_type’ or ‘leiden’.

  • fill (str | None, default None) – Fill aesthetic to split the histogram (categorical). Shortcut for mapping=aes(fill=…) e,g., ‘cell_type’ or ‘leiden’.

  • bins (int | None, default None) – Number of bins. Overridden by binwidth if both are provided.

  • binwidth (float | None, default None) – Width of each bin. Takes precedence over bins.

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

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

  • geom_fill (str | None, default None) – Fill color for all bars in the histogram.

  • geom_color (str | None, default None) – Border color for all bars in the histogram.

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

  • variable_column (str, default 'variable') – The name of the variable column in the dataframe.

  • value_column (str, default 'value') – The name of the value column in the dataframe.

  • share_ticks (bool, default False) – Whether to share the ticks across all plots. If True, only X tick texts on bottom row and Y tick text on left column are shown.

  • share_axis (bool, default False) – Whether to share the axis across all plots. If True, only X axis on bottom row and Y axis on left column is shown.

  • layers (Sequence[FeatureSpec | LayerSpec] | FeatureSpec | LayerSpec | None, default None) – Additional layers to add to the plot.

  • ncol (int, default None) – Number of columns in grid. If not specified, shows plots horizontally, in one row.

  • sharex (bool, default None) – Controls sharing of axis limits between subplots in the grid. all/True - share limits between all subplots. none/False - do not share limits between subplots. row - share limits between subplots in the same row. col - share limits between subplots in the same column.

  • sharey (bool, default None) – Controls sharing of axis limits between subplots in the grid. all/True - share limits between all subplots. none/False - do not share limits between subplots. row - share limits between subplots in the same row. col - share limits between subplots in the same column.

  • widths (list[float], default None) – Relative width of each column of grid, left to right.

  • heights (list[float], default None) – Relative height of each row of grid, top-down.

  • hspace (float | None, default None) – Cell horizontal spacing in px.

  • vspace (float | None, default None) – Cell vertical spacing in px.

  • fit (bool, default True) – Whether to stretch each plot to match the aspect ratio of its cell (fit=True), or to preserve the original aspect ratio of plots (fit=False).

  • align (bool, default False) – If True, align inner areas (i.e. “geom” bounds) of plots. However, cells containing other (sub)grids are not participating in the plot “inner areas” layouting.

  • guides (str, default 'auto') –

    Specifies how guides (legends and colorbars) should be treated in the layout.
    • ’collect’ collect guides from all subplots, removing duplicates.

    • ’keep’ keep guides in their original subplots; do not collect at this level.

    • ’auto’ allow guides to be collected if an upper-level layout uses guides=’collect’;

    otherwise, keep them in subplots.

    For more information on gggrid parameters: https://lets-plot.org/python/pages/api/lets_plot.gggrid.html

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

Returns:

SupPlotsSpec – Histograms.

Examples

Histograms.

import scanpy as sc
from lets_plot import *

import cellestial as cl

data = cl.datasets.pbmc3k()

cl.histograms(
    data,
    ["n_genes_by_counts", "log1p_total_counts_mt"],
    fill="cell_type_lvl1",
    bins=40,
    ncol=2,
    guides="collect",
)