The plotting (pl) accessor

The plotting (pl) accessor#

The plotting accessor provides functions for visualizing segmentation results, such as cell type proportions and UMAP embeddings.

segtraq.pl.plotting.boxplot(method_to_segtraq: dict[str, object], celltype_col: str, value_key: str, method_palette: Mapping[str, str] | None = None, x_order: list[str] | None = None, table_key: str = 'table', title: str | None = None, dropna: bool = True, missing_label: str = 'None', save: str | None = None) DataFrame#

Boxplots per segmentation method, with cell types on the x-axis.

Parameters:
  • method_to_segtraq (dict[str, object]) – A dictionary mapping segmentation method names to SegTraQ objects.

  • celltype_col (str) – The column name in adata.obs that contains cell type labels.

  • value_key (str) – The column name in adata.obs that contains the values to plot.

  • method_palette (Mapping[str, str] | None, optional) – A mapping from segmentation method names to colors. If None, a default palette is used.

  • x_order (list[str] | None, optional) – The order of cell types on the x-axis. If None, cell types are sorted alphabetically.

  • table_key (str, optional) – The key to access the AnnData table in the SegTraQ object.

  • title (str | None, optional) – The title of the plot. If None, no title is set.

  • dropna (bool, optional) – Whether to drop NaN values in the value column.

  • missing_label (str, optional) – The label to use for missing cell type annotations.

  • save (str | None, optional) – If provided, the path to save the plot. If None, the plot is shown.

segtraq.pl.plotting.boxplot_combined(method_to_segtraq: dict[str, object], celltype_col: str, value_key: str, method_palette: Mapping[str, str] | None = None, table_key: str = 'table', x_order: list[str] | None = None, title: str | None = None, dropna: bool = True, missing_label: str = 'None', save: str | None = None) DataFrame#

Combined boxplot with all methods overlaid, with cell types on the x-axis.

Parameters:
  • method_to_segtraq (dict[str, object]) – A dictionary mapping segmentation method names to SegTraQ objects.

  • celltype_col (str) – The column name in adata.obs that contains cell type labels.

  • value_key (str) – The column name in adata.obs that contains the values to plot.

  • method_palette (Mapping[str, str] | None, optional) – A mapping from segmentation method names to colors. If None, a default palette is used.

  • table_key (str, optional) – The key to access the AnnData table in the SegTraQ object.

  • x_order (list[str] | None, optional) – The order of cell types on the x-axis. If None, cell types are sorted alphabetically.

  • title (str | None, optional) – The title of the plot. If None, a default title is used.

  • dropna (bool, optional) – Whether to drop NaN values in the value column.

  • missing_label (str, optional) – The label to use for missing cell type annotations.

  • save (str | None, optional) – If provided, the path to save the plot. If None, the plot is shown.

segtraq.pl.plotting.celltype_proportions(method_to_segtraq: dict[str, object], celltype_col: str, ct_palette: Mapping[str, str] | None = None, title: str = 'Cell-type proportions', table_key: str = 'table', include_zeros: bool = True, missing_label: str = 'None', save: str | None = None) DataFrame#

Plots a stacked barplot of cell type proportions per segmentation method.

Parameters:
  • method_to_segtraq (dict[str, object]) – A dictionary mapping segmentation method names to SegTraQ objects.

  • celltype_col (str) – The column name in adata.obs that contains cell type labels.

  • ct_palette (Mapping[str, str] | None, optional) – A mapping from cell type names to colors. If None, a default palette is used.

  • title (str, optional) – The title of the plot.

  • table_key (str, optional) – The key to access the AnnData table in the SegTraQ object.

  • include_zeros (bool, optional) – Whether to include cell types with zero counts in the plot.

  • missing_label (str, optional) – The label to use for missing cell type annotations.

  • save (str | None, optional) – If provided, the path to save the plot. If None, the plot is shown.

segtraq.pl.plotting.umap(method_to_segtraq: dict[str, object], color: str, palette: Mapping[str, str] | None = None, table_key: str = 'table', umap_key: str = 'X_umap', point_size: float = 6.0, figsize: tuple[float, float] | None = None, cols: int = 3, legend: bool = False, cmap: str = 'viridis', save: str | None = None) DataFrame#

UMAP scatter plots per segmentation method, colored by a specified column. One global legend or colorbar is used.