classification_plot()
Create a classification plot with flexible display options.
Usage
classification_plot(
df,
classes,
conditions,
condition_col="condition",
class_col="Class",
selector_col="cell_line",
selector_val=None,
show_triplicates=False,
fig_size=(7, 7),
size_units="cm",
y_lim=(0, 100),
title=None,
colors=COLORS,
axes=None,
bar_width=0.75,
show_legend=True,
legend_bbox=(0.98, 1.0),
group_size=1,
repeat_offset=0.18,
within_group_spacing=0.2,
between_group_gap=0.4,
show_boxes=True,
show_significance=True,
stats_class=None,
paired=True,
show_ns=True,
min_effect=None,
save=False,
save_stats=False,
path=None,
file_format="pdf",
tight_layout=True,
dpi=300
)The plot behavior changes based on parameters: - show_triplicates=“stacked”: Shows stacked bars with error bars - show_triplicates=“triplicates”: Shows individual repeat bars - group_size > 1: Groups conditions together (works with triplicates mode)
Data Filtering df : pd.DataFrame DataFrame containing classification data classes : list[str] List of class names to plot conditions : list[str] List of condition names to plot condition_col : str, default=“condition” Column name for experimental condition class_col : str, default=“Class” Column name for class/category (dynamic based on model) selector_col : str | None, default=“cell_line” Column name for selector (e.g., cell line) selector_val : str | None, default=None Value to filter selector_col by
Display Options ^ show_triplicates : bool, default=False If False, shows stacked bars with error bars (mean ± SD). If True, shows individual replicate bars side-by-side. y_lim : tuple[int, int], default=(0, 100) Y-axis limits
Styling & Colors fig_size : tuple[float, float], default=(7, 7) Figure size as (width, height) size_units : str, default=“cm” Units for fig_size (“cm” or “inches”) title : str | None, default=None Plot title colors : list[str], default=COLORS List of colors for plotting axes : Axes | None, default=None Existing axes to plot on
Stacked Mode Settings ^ bar_width : float, default=0.75 Width of bars in stacked mode show_legend : bool, default=True Whether to show legend legend_bbox : tuple[float, float], default=(0.98, 1.0) Legend position as (x, y)
Triplicates Mode Settings ^ group_size : int, default=1 Number of conditions to group (1 = no grouping) repeat_offset : float, default=0.18 Offset for repeat bars within_group_spacing : float, default=0.2 Spacing within groups between_group_gap : float, default=0.4 Gap between groups show_boxes : bool, default=True Whether to draw a box around each condition’s triplicate bars (only applies when show_triplicates=True). Set False for a cleaner look when the bars do not sum to 100% (e.g. a single class selected). show_significance : bool, default=True Whether to compute significance (condition vs the first in the group, paired by plate). Exports a p-value and a medians CSV when save=True. stats_class : str | None, default=None Which class’s comparison to annotate on the plot (default = the first class in classes). Both CSV tables always cover every class. paired : bool, default=True Use a paired t-test (ttest_rel, matched by plate_id); set False for the unpaired ttest_ind.
Save Options save : bool, default=False 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 : Path | None, default=None Path to save the plot file_format : str, default=“pdf” File format for saving tight_layout : bool, default=True Whether to use tight layout dpi : int, default=300 Resolution for saving
Returns
tuple[Figure, Axes]- Tuple of (figure, axes)
Examples
Stacked plot with error bars (default)
fig, ax = classification_plot( df, [“G1”, “S”, “G2M”], [“Control”, “Treatment”] )
Individual triplicates without grouping
fig, ax = classification_plot( df, [“G1”, “S”, “G2M”], [“Control”, “Treatment”], show_triplicates=True )
Individual triplicates with grouping
fig, ax = classification_plot( df, [“G1”, “S”, “G2M”], [“Control”, “Treat1”, “Treat2”, “Treat3”], show_triplicates=True, group_size=2 # Groups conditions in pairs )