feature_norm_plot()
Create a normalized feature plot with threshold-based stacked bars.
Usage
feature_norm_plot(
df,
feature,
conditions,
axes=None,
x_label=True,
condition_col="condition",
selector_col="cell_line",
selector_val="",
title="",
color_scheme="green",
legend=False,
fig_size=(8, 6),
size_units="cm",
normalize_by_plate=True,
threshold=1.5,
save_norm_qc=False,
show_triplicates=False,
show_error_bars=True,
show_boxes=True,
group_size=1,
within_group_spacing=0.2,
between_group_gap=0.5,
paired=True,
show_ns=True,
scatter_size=7.0,
min_effect=None,
save=True,
save_stats=False,
path=None,
tight_layout=False,
file_format="pdf",
dpi=300
)This plot normalizes the feature data by mode (peak=1.0) and displays the proportion of cells above/below a threshold as stacked bars. Optionally shows individual triplicate data with boxes.
df : pd.DataFrame The dataframe containing single-cell measurements. feature : str The feature column to normalize and plot. conditions : list[str] The conditions to plot. axes : Optional[Axes], default=None The axis to plot on. x_label : bool, default=True Whether to show the x-label. condition_col : str, default=“condition” The column name for the conditions. selector_col : Optional[str], default=“cell_line” The column name for the selector. selector_val : Optional[str], default=“” The value of the selector. title : Optional[str], default=“” The title of the plot. color_scheme : str, default=“green” Color scheme for positive/negative categories. Options: - “green”: Olive (positive) and Light Green (negative) - “blue”: Blue (positive) and Light Blue (negative) - “purple”: Purple (positive) and Lavender (negative) Invalid values default to “green”. legend : bool, default=False Whether to show the default plate legend. Default False since norm plots have their own threshold legend. fig_size : tuple[float, float], default=(8, 6) The size of the figure. size_units : str, default=“cm” The units of the figure size. normalize_by_plate : bool, default=True Whether to normalize within each plate. threshold : float, default=1.5 The threshold value (times mode). save_norm_qc : bool, default=False Whether to save normalization QC plots. QC plots show the intensity distributions before/after normalization to document the process. Saved to the same path as the main plot with suffix “_norm_qc”. show_triplicates : bool, default=False Whether to show individual triplicate bars. show_error_bars : bool, default=True Whether to show error bars on summary bars. show_boxes : bool, default=True Whether to draw boxes around triplicates. group_size : int, default=1 The number of conditions to group. paired : bool, default=True Use a paired t-test (ttest_rel, matched by plate_id) for significance; set False for the unpaired ttest_ind. within_group_spacing : float, default=0.2 The spacing between conditions within a group. between_group_gap : float, default=0.5 The gap between groups. save : bool, default=True Whether to save the plot. save_stats : bool, default=False Write {title}_stats.csv and {title}_medians.csv to path (independent of save; works when plotting onto a provided/composed axes). path : Optional[Path], default=None The path to save the plot. tight_layout : bool, default=False Whether to use tight layout. file_format : str, default=“pdf” The format of the saved figure. dpi : int, default=300 The resolution of the saved figure.
tuple[Figure, Axes] The figure and axes objects.
>>> # Basic normalized feature plot with default green scheme
>>> fig, ax = feature_norm_plot(
... df=df,
... feature="intensity_mean_p21_nucleus",
... conditions=["control", "treatment1", "treatment2"],
... )>>> # Blue color scheme with individual triplicates
>>> fig, ax = feature_norm_plot(
... df=df,
... feature="intensity_mean_p21_nucleus",
... conditions=["control", "treatment1", "treatment2"],
... color_scheme="blue",
... show_triplicates=True,
... threshold=2.0, # Custom threshold at 2x mode
... )>>> # Purple color scheme for publication
>>> fig, ax = feature_norm_plot(
... df=df,
... feature="intensity_mean_p21_nucleus",
... conditions=["control", "treatment1", "treatment2"],
... color_scheme="purple",
... )