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, celltype_col, value_key, method_palette=None, x_order=None, table_key='table', title=None, dropna=True, missing_label='None', save=None)#

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, celltype_col, value_key, method_palette=None, table_key='table', x_order=None, title=None, dropna=True, missing_label='None', save=None)#

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, celltype_col, ct_palette=None, title='Cell-type proportions', table_key='table', include_zeros=True, missing_label='None', save=None)#

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, features, axes=('centroid_x', 'centroid_y'), filter_size=21, tables_key='table')#

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 (SpatialData) – A SpatialData object containing an AnnData table.

  • features (str or list/tuple of str) – One or more column names from adata.obs to plot.

  • axes (list/tuple of str, optional) – Columns in adata.obs to 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, axes=('x', 'y'), filter_size=21, points_key='transcripts')#

Plot the marginal distribution of transcripts along one or more spatial axes.

Parameters:
  • sdata (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.points that 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, color, palette=None, table_key='table', umap_key='X_umap', point_size=6.0, figsize=None, cols=3, legend=False, cmap='viridis', save=None)#

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