squidpy.pl.spatial_segment

squidpy.pl.spatial_segment(adata, color=None, groups=None, library_id=None, library_key=None, spatial_key='spatial', img=True, img_res_key='hires', img_alpha=None, img_cmap=None, img_channel=None, seg=None, seg_key='segmentation', seg_cell_id=None, seg_contourpx=None, seg_outline=False, use_raw=None, layer=None, alt_var=None, crop_coord=None, cmap=None, palette=None, alpha=1.0, norm=None, na_color=(0, 0, 0, 0), connectivity_key=None, edges_width=1.0, edges_color='grey', library_first=True, frameon=None, wspace=None, hspace=0.25, ncols=4, outline=False, outline_color=('black', 'white'), outline_width=(0.3, 0.05), legend_loc='right margin', legend_fontsize=None, legend_fontweight='bold', legend_fontoutline=None, legend_na=True, colorbar=True, scalebar_dx=None, scalebar_units=None, title=None, axis_label=None, fig=None, ax=None, return_ax=False, figsize=None, dpi=None, save=None, scalebar_kwargs=mappingproxy({}), edges_kwargs=mappingproxy({}), **kwargs)[source]

Plot spatial omics data with segmentation masks on top.

Argument seg_cell_id in anndata.AnnData.obs controls unique segmentation mask’s ids to be plotted. By default, 'segmentation', seg_key for the segmentation and 'hires' for the image is attempted.

  • Use seg_key to display the image in the background.

  • Use seg_contourpx or seg_outline to control how the segmentation mask is displayed.

Use library_id to select the image. If multiple library_id are available, use library_key in anndata.AnnData.obs to plot the subsets. Use crop_coord to crop the spatial plot based on coordinate boundaries.

This function has few key assumptions about how coordinates and libraries are handled:

  • The arguments library_key and library_id control which dataset is plotted. If multiple libraries are present, specifying solely library_key will suffice, and all unique libraries will be plotted sequentially. To select specific libraries, use the library_id argument.

  • The argument color controls which features in obs/var are plotted. They are plotted for all available/specified libraries. The argument groups can be used to select categories to be plotted. This is valid only for categorical features in anndata.AnnData.obs.

  • If multiple library_id are available, arguments such as size and crop_coord accept lists to selectively customize different library_id plots. This requires that the length of such lists matches the number of unique libraries in the dataset.

  • Coordinates are in the pixel space of the source image, so an equal aspect ratio is assumed.

  • The origin (0, 0) is on the top left, as is common convention with image data.

  • The plotted points (dots) do not have a real “size” but it is relative to their coordinate/pixel space. This does not hold if no image is plotted, then the size corresponds to points size passed to matplotlib.axes.Axes.scatter().

If anndata.AnnData.uns ['spatial'] is present, use img_key, seg_key and size_key arguments to find values for img, seg and size. Alternatively, these values can be passed directly via img.

See also

Parameters:
Return type:

Axes | Sequence[Axes] | None

Returns:

: Nothing, just plots the figure and optionally saves the plot.