voyagerpy.plotting.plot_spatial_feature#

voyagerpy.plotting.plot_spatial_feature(adata: AnnData, features: str | Sequence[str], ncol: int = 2, barcode_geom: str | None = None, barcode_graph_kwargs: Dict | None = None, annot_geom: str | None = None, subset_barcodes: None | slice | Sequence[str] = None, layer: str | None = None, obsm: str | None = None, geom_style: Dict | None = None, annot_style: Dict | None = None, alpha: float = 0.2, divergent: bool = False, color: str | None = None, _ax: None | Axes | Iterable[Axes] = None, legend: bool = True, cmap: str | None = 'Blues7', cat_cmap: str | None = None, div_cmap: str = 'roma', subplot_kwargs: Dict | None = None, legend_kwargs: Dict | None = None, dimension: str = 'barcode', image_kwargs: Dict | None = None, figtitle: str | None = None, feature_labels: None | str | Sequence[str | None] = None, rc_context: Dict[str, Any] | None = None, show_symbol: bool = True, **kwargs) ndarray | ndarray[Any, dtype[Axes]]#

Plot spatial features.

Parameters:
  • adata (AnnData) – The annotated data matrix.

  • features (Union[str, Sequence[str]]) – The features to plot. If an iterable, each feature will be plotted in a separate axis.

  • ncol (int, optional) – The number of columns in the axes grid, by default 2.

  • barcode_geom (Optional[str], optional) – The name of the geometry to use for the barcodes, by default None.

  • barcode_graph_kwargs (Optional[Dict], optional) – If not None, draw a graph on each axis, by default None.

  • annot_geom (Optional[str], optional) – If not None, draw the specified geometry, e.g. tissue segmentation, by default None.

  • subset_barcodes (Union[None, slice, Sequence[str]], optional) – The subset of barcodes to include in the plot, by default None

  • layer (Optional[str], optional) – The layer to use. If None, use adata.X, by default None.

  • obsm (Optional[str], optional) – The obsm to use. If None, use adata.obs, by default None

  • geom_style (Optional[Dict], optional) – Style dictionary to use when plotting barcode geometry as polygons, by default None.

  • annot_style (Optional[Dict], optional) – Style dictionary to use when plotting the annotation geometry, by default {}

  • alpha (float, optional) – _description_, by default 0.2

  • divergent (bool, optional) – Whether to use a divergent colormap, by default False

  • color (Optional[str], optional) – _description_, by default None

  • _ax (Union[None, Axes, Iterable[Axes]], optional) – The axes to use. If not None, must match the number of plots created. Otherwise, the axes will be created, by default None

  • legend (bool, optional) – Whether to add a legend to the figure, by default True

  • cmap (Optional[str], optional) – The colormap to use for continuous values, by default “Blues7”.

  • cat_cmap (Optional[str], optional) – The colormap to use for categorical values, by default None.

  • div_cmap (str, optional) – The colormap to use for continuous values when divergent is True, by default “roma”.

  • subplot_kwargs (Optional[Dict], optional) – Keyword arguments to pass to configure_subplots(), by default None

  • legend_kwargs (Optional[Dict], optional) – Keyword arguments for creating the legend, by default None. Will be passed to geopandas.GeoDataFrame.plot() if the supplied barcode geometry is a Series of polygons, else to vp.plt.scatter().

  • dimension (str, optional) – Describes what type of data to plot. If “barcode”, then the barcode geometries are used, else if “gene”, gene geometries are used. Otherwise, the geometry dataframe used is adata.uns["spatial"]["geometry"][dimension]. by default “barcode”.

  • image_kwargs (Optional[Dict], optional) –

    If not None, show the tissue image behind the scattered points, by default None. The keys used from this dict are

    • ”crop”: bool, whether to crop the image by the positions of the scatter points.

    • ”pad”: int, the number of pixels to pad the cropped image by. Effictively enlarges the crop.

  • figtitle (Optional[str], optional) – The title of the figure, by default None

  • feature_labels (Union[None, str, Sequence[Optional[str]]], optional) – The labels to show on each subplot, by default None

  • rc_context (Optional[Dict[str, Any]], optional) – Styling dict for overriding styles with matplotlib.pyplot.rc_context(), by default None

  • show_symbol (bool, optional) – Show gene symbols, by default True

Returns:

The axis or axes used for plotting.

Return type:

Union[np.ndarray, npt.NDArray[Axes]]

Raises:
  • KeyError – If the supplied obsm is not found in adata.obsm.

  • ValueError – If the supplied features are not found in adata.var_names and not in the dataframe used.

  • ValueError – If the supplied barcode_geom if not found in the geometry dataframe.

  • ValueError – If the supplied annot_geom if not found in the adata.uns["spatial"]["geom"] geometry dataframe.