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 insdatafor which instance sizes are visualized.microns_per_pixel (
float(default:1)) – Pixel size used to convert areas from pixels to square microns. When set to1, instance sizes are reported in pixels.ax (
Axes|None(default:None)) – Matplotlib axes to draw on. IfNone, a new figure and axes are created.bins (
int|str(default:'auto')) – Histogram bin specification passed toseaborn.histplot().histplot_kwargs (
Mapping[str,Any] (default:mappingproxy({}))) – Keyword arguments passed toseaborn.histplot().median_line_kwargs (
Mapping[str,Any] (default:mappingproxy({}))) – Keyword arguments passed tomatplotlib.axes.Axes.axvline()for the median guide line.median_text_kwargs (
Mapping[str,Any] (default:mappingproxy({}))) – Keyword arguments passed tomatplotlib.axes.Axes.text()for the median annotation.figsize (
tuple[float,float] (default:(5.5, 4.5))) – Figure size used whenaxisNone.title (
str|None(default:None)) – Plot title. IfNone, no title is added.color (
str|None(default:None)) – Histogram color. IfNone, a default color is used.show_median (
bool(default:True)) – IfTrue, add a dashed median line and annotate the median.show_std (
bool(default:True)) – IfTrue, include the standard deviation in the annotation box.ylabel (
str|None(default:None)) – Y-axis label. IfNone,"Number of instances"is used.
- Return type:
- Returns:
:
matplotlib.axes.Axescontaining 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, )