cellestial.boxplot#

boxplot(data: AnnData, key: str | Sequence[str], *, mapping: FeatureSpec | None = None, axis: Literal[0, 1] | None = None, color: str | None = None, fill: str | None = None, threshold: float | None = None, add_keys: Sequence[str] | str | None = None, tooltips: Literal['none'] | Sequence[str] | FeatureSpec | None = None, geom_fill: str | None = '#FF00FF', geom_color: str | None = '#2f2f2f', point_color: str = '#1f1f1f', point_alpha: float = 0.7, point_size: float = 0.5, point_geom: Literal['jitter', 'point', 'sina'] = 'jitter', observations_name: str = 'Barcode', variables_name: str = 'Variable', show_points: bool = True, interactive: bool = False, value_column: str = 'value', variable_column: str = 'variable', point_kwargs: dict[str, Any] | None = None, **geom_kwargs) PlotSpec#

Boxplot.

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

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

  • 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 boxplot (categorical). e,g., ‘cell_type’ or ‘leiden’.

  • fill (str | None, default None) – Fill aesthetic to split the boxplot (categorical). e,g., ‘cell_type’ or ‘leiden’.

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

  • 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 '#FF00FF') –

    Fill color for all boxplots in the boxplot. - Accepts:

    • hex code e.g. ‘#f1f1f1’

    • color name (of a limited set of colors).

    • RGB/RGBA e.g. ‘rgb(0, 0, 255)’, ‘rgba(0, 0, 255, 0.5)’.

  • geom_color (str | None, default '#2f2f2f') –

    Border color for all boxplots in the boxplot. - Accepts:

    • hex code e.g. ‘#f1f1f1’

    • color name (of a limited set of colors).

    • RGB/RGBA e.g. ‘rgb(0, 0, 255)’, ‘rgba(0, 0, 255, 0.5)’.

  • point_color (str, default '#1f1f1f') –

    Color for the points in the boxplot. - Accepts:

    • hex code e.g. ‘#f1f1f1’

    • color name (of a limited set of colors).

    • RGB/RGBA e.g. ‘rgb(0, 0, 255)’, ‘rgba(0, 0, 255, 0.5)’.

  • point_alpha (float, default 0.7) – Alpha (transparency) for the points in the boxplot.

  • point_size (float, default 0.5) – Size for the points in the boxplot.

  • point_geom ({'jitter','point','sina'}, default is 'jitter') – Geom type of the points, default is geom_jitter.

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

  • show_points (bool, default True) – Whether to show points.

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

  • point_kwargs (dict[str, Any] | None, default None) – Additional parameters for the geom_point layer. For more information on geom_point parameters, see: https://lets-plot.org/python/pages/api/lets_plot.geom_point.html

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

Returns:

PlotSpec – Boxplot.

Examples

import cellestial as cl
import scanpy as sc

from lets_plot import *

data = sc.read_h5ad('data/pbmc3k_pped.h5ad')

boxplot = (
    cl.boxplot(
        data,
        "CD14",
        fill="cell_type_lvl1",
        point_size=2,
        threshold=0.1,
    )
    + ggsize(800, 400)
    + scale_fill_brewer(palette="Set2")
    + guides(fill=guide_legend(ncol=2))
)

boxplot

Remove the points.

import cellestial as cl
import scanpy as sc

from lets_plot import *

data = sc.read_h5ad('data/pbmc3k_pped.h5ad')

boxplot = (
    cl.boxplot(
        data,
        "CD14",
        fill="cell_type_lvl1",
        point_size=2,
        threshold=0.1,
        show_points=False,
    )
    + ggsize(800, 400)
    + scale_fill_brewer(palette="Set2")
    + guides(fill=guide_legend(ncol=2))
)

boxplot

Providing a list of keys.

import cellestial as cl
import scanpy as sc

from lets_plot import *

data = sc.read_h5ad('data/pbmc3k_pped.h5ad')

boxplot = (
    cl.boxplot(
        data,
        ["pct_counts_in_top_200_genes", "n_genes_by_counts"],
        fill="cell_type_lvl1",
        point_size=0.3,
        point_alpha=0.4,
    )
    + scale_y_log2()
    + ggsize(800, 400)
)
boxplot