squidpy.pl.spatial_scatter(adata, shape=None, 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, use_raw=None, layer=None, alt_var=None, size=None, size_key='spot_diameter_fullres', scale_factor=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 data overlayed on top.

The plotted shapes (circles, squares or hexagons) have a real “size” with respect to their coordinate space, which can be specified via the size or size_key argument.

  • Use img_key to display the image in the background.

  • Use library_id to select the image. By default, 'hires' is attempted.

  • Use img_alpha, img_cmap and img_channel to control how it is displayed.

  • Use size to scale the size of the shapes plotted on top.

If no image is plotted, it defaults to a scatter plot, see matplotlib.axes.Axes.scatter().

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

Return type

Union[Axes, Sequence[Axes], None]


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