pcas#
API pages include interactive (HTML) plots that would possibly not render correctly on a mobile device.
- pcas(data: AnnData, keys: Sequence[str], *, mapping: FeatureSpec | None = None, use_key: str | None = None, xy: tuple[int, int] | Sequence[int] = (1, 2), size: float | None = 0.8, variable_keys: Sequence[str] | str | None = None, add_columns: 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, interactive: bool = False, observations_name: str = 'Barcode', color_low: str = '#e6e6e6', color_mid: str | None = None, color_high: str = '#377eb8', mid_point: Literal['mean', 'median', 'mid'] | float = 'median', axis_type: Literal['axis', 'arrow'] | None = None, arrow_length: float = 0.25, arrow_size: float = 1, arrow_color: str = '#3f3f3f', arrow_angle: float = 10, legend_ondata: bool = False, ondata_size: float = 12, ondata_color: str = '#3f3f3f', ondata_fontface: str = 'bold', ondata_family: str = 'sans', ondata_alpha: float = 1, ondata_label: bool = False, share_labels: bool = False, share_axis: 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', **point_kwargs) SupPlotsSpec#
Grid of dimensionality reduction plots.
- Parameters:
data (
AnnData) – The AnnData object of the single cell data.keys (
list[str] | tuple[str] | Sequence[str]) – The keys (cell features) to color the points by. e.g., ‘leiden’ or ‘louvain’ to color by clusters or gene name for expression.mapping (
FeatureSpec | None, defaultNone) – Additional aesthetic mappings for the plot, the result of aes().xy (
tuple[int,int] | Sequence[int], default(1,2)) – The x and y axes to use for the plot. e.g., (1, 2) for UMAP1 and UMAP2.use_key (
str, defaultNone) – The specific key to use for the desired dimensions. e.g., ‘X_umap_2d’ or ‘X_pca_2d’. Otherwise, the function will decide on the key based on the dimensions.size (
float | None, default0.8) – The size of the points.variable_keys (
str | Sequence[str] | None, defaultNone) – Variable keys to add to the DataFrame. If None, no additional keys are added.add_columns (
str | Sequence[str] | None, defaultNone) – Extra metadata columns or variable names to materialise into the shared frame, on top of those inferred from keys, mapping, and tooltips.groups (
str | Sequence[str] | None, defaultNone) – Show only specific groups, keeping points where the colored key matches any of them. Categorical keys only.drop (
str | Sequence[str] | None, defaultNone) – Drop specific groups, filtering out points where the colored key matches any of them. Categorical keys only.tooltips (
{'none'}| Sequence[str] | FeatureSpec | None, defaultNone) – 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.interactive (
bool, defaultFalse) – Whether to make the plot interactive.cluster_name (
str, default'Cluster') – The name to overwrite the clustering key in the dataframe and the plot.observations_name (
str, default'Barcode') – The name to give to barcode (or index) column in the dataframe.color_low (
str, default'#e6e6e6') – The color to use for the low end of the color gradient.color_mid (
str, defaultNone) – The color to use for the middle part of the color gradient.color_high (
str, default'#377EB8') – The color to use for the high end of the color gradient.mid_point (
{'mean', 'median', 'mid'}| float, default'median') – The midpoint (in data value) of the color gradient. Can be ‘mean’, ‘median’ and ‘mid’ or a number (float or int). - If ‘mean’, the midpoint is the mean of the data. - If ‘median’, the midpoint is the median of the data. - If ‘mid’, the midpoint is the mean of ‘min’ and ‘max’ of the data.axis_type (
{'axis', 'arrow'}| None) – Whether to use regular axis or arrows as the axis.arrow_length (
float, default0.25) – Span of each axis line as a fraction of its data range (0.25 covers 25%).arrow_size (
float, default1) – Width of the axis lines.arrow_color (
str, default'#3f3f3f') – Color of the arrows.arrow_angle (
float, default10) – Angle of the arrow head in degrees.legend_ondata (
bool, defaultFalse) – whether to show legend on dataondata_size (
float, default12) – size of the legend (text) on data.ondata_color (
str, default'#3f3f3f') – color of the legend (text) on dataondata_fontface (
str, default'bold') – fontface of the legend (text) on data. https://lets-plot.org/python/pages/aesthetics.html#font-faceondata_family (
str, default'sans') – family of the legend (text) on data. https://lets-plot.org/python/pages/aesthetics.html#font-familyondata_alpha (
float, default1) – alpha (transparency) of the legend on data.ondata_label (
bool, defaultFalse) – Whether to draw on-data legends with a filled label background.share_labels (
bool, defaultFalse) – Whether to share the labels across all plots. If True, only X labels on bottom row and Y labels on left column are shown.share_axis (
bool, defaultFalse) – 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, defaultNone) – Layers to add to all the plots in the grid.ncol (
int, defaultNone) – Number of columns in grid. If not specified, shows plots horizontally, in one row.sharex (
bool, defaultNone) – 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, defaultNone) – 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], defaultNone) – Relative width of each column of grid, left to right.heights (
list[float], defaultNone) – Relative height of each row of grid, top-down.hspace (
float | None, defaultNone) – Cell horizontal spacing in px.vspace (
float | None, defaultNone) – Cell vertical spacing in px.fit (
bool, defaultTrue) – 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, defaultFalse) – 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. Duplicates are identified by comparing visual properties: For legends: title, labels, and all aesthetic values (colors, shapes, sizes, etc.). For colorbars: title, domain limits, breaks, and color gradient.
For more information on gggrid parameters: https://lets-plot.org/python/pages/api/lets_plot.gggrid.html
**point_kwargs – 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
- Returns:
SupPlotsSpec– Grid of dimensionality reduction plots.
Examples
Grid of dimensionality reduction plots via multiple keys.
import scanpy as sc from lets_plot import * import cellestial as cl data = cl.datasets.pbmc3k(cache_directory="data") cl.pcas( data, keys=["cell_type_lvl1", "sample", "MALAT1", "YBX3"], axis_type="arrow", color_high="red", ncol=2, )