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.feature_distribution_across_space(sdata: SpatialData, features: str | tuple[str] | list[str], axes: tuple[str] | list[str] = ('centroid_x', 'centroid_y'), filter_size: int = 21, tables_key: str = 'table') list[list[Axes]]#
Plot the distribution of one or more obs features across spatial axes.
For each feature, one subplot per axis is shown, arranged as a grid of shape (n_features, n_axes).
- Parameters:
sdata (sd.SpatialData) – A SpatialData object containing an AnnData table.
features (str or list/tuple of str) – One or more column names from
adata.obsto plot.axes (list/tuple of str, optional) – Columns in
adata.obsto use as spatial axes. Default is('centroid_x', 'centroid_y').filter_size (int, optional) – Size of the filter kernel. Default is 21.
tables_key (str, optional) – Key inside
sdata.tables. Default is'table'.
- Returns:
Nested list of shape [n_features][n_axes].
- Return type:
list of list of matplotlib.axes.Axes
- Raises:
ValueError – If any requested feature or axis is not found in obs.
- segtraq.pl.plotting.transcript_distribution_across_space(sdata: SpatialData, axes: str | tuple[str] | list[str] = ('x', 'y'), filter_size: int = 21, points_key: str = 'transcripts') Axes | list[Axes]#
Plot the marginal distribution of transcripts along one or more spatial axes.
- Parameters:
sdata (sd.SpatialData) – A SpatialData object containing a points element with transcript coordinates.
axes (str or list/tuple of str, optional) – Spatial axis or axes to plot. Default is (‘x’, ‘y’).
filter_size (int, optional) – Size of the filter kernel. Default is 21.
points_key (str, optional) – Key inside
sdata.pointsthat holds the transcript DataFrame. Default is'transcripts'.
- Returns:
The Axes containing the plot(s). Returns a single Axes if a single axis string was passed, otherwise a list.
- Return type:
matplotlib.axes.Axes or list of matplotlib.axes.Axes
- Raises:
ValueError – If any of the requested axes are not present in the points DataFrame.
- 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.