harpy.qc.segmentation_histogram

harpy.qc.segmentation_histogram#

harpy.qc.segmentation_histogram(sdata, labels_name, microns_per_pixel=1, ax=None, bins='auto', histplot_kwargs=mappingproxy({}), median_line_kwargs=mappingproxy({}), median_text_kwargs=mappingproxy({}), figsize=(5.5, 4.5), title=None, color=None, show_median=True, show_std=True, ylabel=None)#

Plot a histogram of segmented instance sizes for a labels element.

The histogram is computed from per-instance areas extracted from the selected segmentation mask. Areas can be reported either in pixels or in square microns depending on microns_per_pixel.

Parameters:
  • sdata (SpatialData) – SpatialData object containing the segmentation labels element.

  • labels_name (str) – Name of the labels element in sdata for which instance sizes are visualized.

  • microns_per_pixel (float (default: 1)) – Pixel size used to convert areas from pixels to square microns. When set to 1, instance sizes are reported in pixels.

  • ax (Axes | None (default: None)) – Matplotlib axes to draw on. If None, a new figure and axes are created.

  • bins (int | str (default: 'auto')) – Histogram bin specification passed to seaborn.histplot().

  • histplot_kwargs (Mapping[str, Any] (default: mappingproxy({}))) – Keyword arguments passed to seaborn.histplot().

  • median_line_kwargs (Mapping[str, Any] (default: mappingproxy({}))) – Keyword arguments passed to matplotlib.axes.Axes.axvline() for the median guide line.

  • median_text_kwargs (Mapping[str, Any] (default: mappingproxy({}))) – Keyword arguments passed to matplotlib.axes.Axes.text() for the median annotation.

  • figsize (tuple[float, float] (default: (5.5, 4.5))) – Figure size used when ax is None.

  • title (str | None (default: None)) – Plot title. If None, no title is added.

  • color (str | None (default: None)) – Histogram color. If None, a default color is used.

  • show_median (bool (default: True)) – If True, add a dashed median line and annotate the median.

  • show_std (bool (default: True)) – If True, include the standard deviation in the annotation box.

  • ylabel (str | None (default: None)) – Y-axis label. If None, "Number of instances" is used.

Return type:

Axes

Returns:

: matplotlib.axes.Axes containing the histogram.

Raises:

ValueError – If the selected labels element does not contain any labeled instances.

Examples

import harpy as hp

sdata = hp.datasets.pixie_example()

hp.qc.segmentation_histogram(
    sdata,
    labels_name="label_nuclear_fov0",
    microns_per_pixel=1,
)