acia.analysis.properties#
Before/after property-distribution histograms for filtered cell populations.
This module renders a grid of density-normalized histograms for one or more
properties from a property-extractor DataFrame (the output of
acia.analysis.ExtractorExecutor), optionally comparing an unfiltered
population against a filtered one (e.g. via
acia.segm.filter.apply_cell_filters()). Properties are laid out as
columns; when a filtered (“after”) DataFrame is given, before/after are
stacked as rows within the same column and share identical bin edges and axis
limits, so outliers can be visually confirmed to “stay or vanish” under
filtering.
- acia.analysis.properties.plot_property_histograms(df_before, properties, *, df_after=None, units=None, bins=50, log_y=False, show_removed=False)[source]#
Plot density-normalized before/after histograms for one or more properties.
Properties are h-stacked as columns. When
df_afteris given, before (row 0) and after (row 1) are v-stacked as rows within each column, and share identical bin edges (computed from the combined range ofdf_before/df_afterfor that property) and identical x/y axis limits, so the two histograms for one property stay directly comparable.- Parameters:
df_before (pd.DataFrame) – the unfiltered (or “before”) property DataFrame, e.g. the output of
acia.analysis.ExtractorExecutor.execute().properties (Sequence[str]) – column names of
df_before(anddf_after, if given) to plot, one column of the grid per property.df_after (pd.DataFrame | None) – optional filtered (or “after”) property DataFrame with the same columns as
df_before. When given, the grid gains a second row per property for direct before/after comparison. WhenNone, onlydf_beforeis plotted (one row).units (dict[str, pint.Unit] | None) – optional column ->
pint.Unitmapping (e.g.acia.analysis.ExtractorExecutor.units) used to format each column’s x-axis label asf"{prop} [{unit:~L}]". Properties missing fromunits(orunits=None) fall back to the bare property name.bins (int) – number of histogram bins (default
50).log_y (bool) – if
True, every Axes’ y-scale is set to"log"(still density-normalized). Default is linear.show_removed (bool) – if
Trueanddf_afteris an index-subset ofdf_before, overlay the filtered-out cells (beforeminusafter) on each “after” histogram as a red step outline, so you can see where in the property’s range the filter cut. Density-normalized (shows location/shape, not count). DefaultFalse.
- Returns:
A matplotlib
Figurewith a1 x len(properties)grid (df_after=None) or2 x len(properties)grid (df_aftergiven) of density histograms. The figure is not shown (noplt.show()).- Raises:
TypeError – if
propertiesis a barestrinstead of a sequence of column names (a plausible typo, e.g."area"instead of["area"], that would otherwise be silently iterated character-by-character).ValueError – if
propertiesis empty. A property with no finite values to plot – an empty population (0 rows), an emptydf_after(all cells filtered out), or an all-NaN column – is not an error: that axis is drawn empty with a “no cells” note.KeyError – if a property in
propertiesis not a column ofdf_before(ordf_after, when given).
- Return type:
Figure