harpy.pl.plot_instance_density

harpy.pl.plot_instance_density#

harpy.pl.plot_instance_density(sdata, table_name, labels_name=None, spatial_key='spatial', bin_size=100, smooth_sigma=None, cmap='cividis', figsize=(8, 8), colorbar=True, ax=None)#

Plot an instance density heatmap from centroids stored in sdata.tables[table_name].obsm[spatial_key].

Parameters:
  • sdata (SpatialData) – SpatialData object.

  • table_name (str) – Table element to plot from sdata.tables.

  • labels_name (str | list[str] | None (default: None)) – Labels element(s) used to select the instances from table_name via the table region key. If None, all observations from table_name are used.

  • spatial_key (str (default: 'spatial')) – Key in adata.obsm containing instance centroid coordinates.

  • bin_size (float (default: 100)) – Width of a histogram bin in the coordinate units stored in adata.obsm[spatial_key].

  • smooth_sigma (float | None (default: None)) – Gaussian smoothing sigma applied to the histogram. If None, no smoothing is applied.

  • cmap (str (default: 'cividis')) – Colormap passed to matplotlib.axes.Axes.imshow().

  • figsize (tuple (default: (8, 8))) – Figure size used when ax is not provided.

  • colorbar (bool (default: True)) – If True, add a colorbar to the figure.

  • ax (Axes | None (default: None)) – matplotlib.axes.Axes object to plot on. If None, a new axes is created via matplotlib.pyplot.subplots().

Return type:

Axes

Returns:

: matplotlib.axes.Axes object.

Examples

>>> import harpy as hp
>>> sdata = hp.datasets.xenium_human_ovarian_cancer(
...     subset=True,
... )
>>> hp.pl.plot_instance_density(
...     sdata,
...     labels_name="cell_labels_global",
...     table_name="table_global",
... )