harpy.pl.plot_transcript_density

harpy.pl.plot_transcript_density#

harpy.pl.plot_transcript_density(sdata, bin_size, points_name, name_gene_column='gene', genes=None, z_plane=None, smooth_sigma=None, cmap='cividis', frac=None, figsize=(8, 8), crd=None, to_coordinate_system='global', colorbar=True, ax=None)#

Plot a transcript density heatmap from a SpatialData object.

Parameters:
  • sdata (SpatialData) – SpatialData object.

  • bin_size (float) – Width of a histogram bin in the units of to_coordinate_system.

  • points_name (str) – Points element to plot from sdata.points.

  • name_gene_column (str | None (default: 'gene')) – Column in the points_name that stores gene identities.

  • genes (str | list[str] | None (default: None)) – Gene or list of genes to visualize. If None, all points are used.

  • z_plane (int | float | None (default: None)) – If provided, filter the points element to rows with z == z_plane. This requires a "z" column on the points element.

  • 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().

  • frac (float | None (default: None)) – Fraction of points to randomly sample for plotting. If None, all points in points_name are visualized.

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

  • crd (tuple[int, int, int, int] | None (default: None)) – The coordinates for the region of interest in the format (xmin, xmax, ymin, ymax), in the coordinate system to_coordinate_system.

  • to_coordinate_system (str (default: 'global')) – Coordinate system in which crd, bin_size, and the plotted axes are interpreted.

  • 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_transcript_density(
...     sdata,
...     points_name="transcripts_global",
...     to_coordinate_system="global_micron",
...     bin_size=10,
... )