cellcycle_stacked()

Create a stacked barplot for cell cycle phase proportions with flexible display modes.

Usage

Source

cellcycle_stacked(
    df,
    conditions,
    condition_col="condition",
    selector_col="cell_line",
    selector_val=None,
    axes=None,
    title=None,
    fig_size=(6, 6),
    size_units="cm",
    colors=None,
    save=False,
    save_stats=False,
    path=None,
    tight_layout=False,
    file_format="pdf",
    dpi=300,
    show_triplicates=False,
    show_error_bars=True,
    show_boxes=True,
    cc_phases=True,
    phase_order=None,
    group_size=1,
    within_group_spacing=0.2,
    between_group_gap=0.5,
    paired=True,
    show_ns=True,
    min_effect=None,
    bar_width=0.5,
    repeat_offset=0.18,
    max_repeats=3,
    x_label=True,
    rotation=45,
    show_legend=True
)

This is a unified wrapper around the new StackedCellCyclePlot class that can create either summary stacked bars (with error bars) or individual triplicate bars (with boxes).

Data Filtering df : pd.DataFrame DataFrame containing cell cycle data with required columns: ‘cell_cycle’, ‘plate_id’, and condition_col. conditions : list[str] List of condition names to plot. condition_col : str, default=“condition” Column name for experimental condition. 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 True, show individual bars for each replicate/plate with boxes. If False, show summary bars with optional error bars. show_error_bars : bool, default=True Whether to show error bars (only applies when show_triplicates=False). show_boxes : bool, default=True Whether to draw boxes around triplicates (only applies when show_triplicates=True). cc_phases : bool, default=True If True, use cell cycle terminology {Sub-G1, G1, S, G2/M, Polyploid}. If False, use DNA content terminology {<2N, 2N, S, 4N, >4N}. phase_order : list[str] | None, default=None Custom list of cell cycle phases to plot. If None, uses all available phases. axes : Axes | None, default=None Matplotlib axis. If None, a new figure is created. x_label : bool, default=True Whether to show the x-axis labels. rotation : int, default=45 Rotation angle for x-axis labels. show_legend : bool, default=True Whether to show the legend with cell cycle phase colors.

Grouping & Layout ^ group_size : int, default=1 Number of conditions per group on the x-axis (1 = no grouping). paired : bool, default=True Use a paired t-test (ttest_rel, matched by plate_id) per phase for the exported stats; set False for the unpaired ttest_ind. The stacked plot draws no on-plot stars — stats are written to {title}_stats.csv / {title}_medians.csv when save=True. within_group_spacing : float, default=0.2 Spacing between bars within a group. between_group_gap : float, default=0.5 Spacing between groups. bar_width : float, default=0.5 Width of each bar. repeat_offset : float, default=0.18 Offset between replicate bars (only applies when show_triplicates=True). max_repeats : int, default=3 Maximum number of replicates to show (only applies when show_triplicates=True).

Styling & Colors title : str | None, default=None Plot title. fig_size : tuple[float, float], default=(6, 6) Dimensions of the figure. size_units : str, default=“cm” Units of the figure size (“cm” or “inch”). colors : list[str] | None, default=None List of colors for plotting phases. tight_layout : bool, default=False Whether to use tight layout.

Save Options save : bool, default=False Whether to save the figure. 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 figure. file_format : str, default=“pdf” Format of the figure. dpi : int, default=300 Resolution of the figure.

tuple[Figure, Axes] The figure and axes objects.

>>> # Simple summary stacked plot with error bars
>>> fig, ax = cellcycle_stacked(
...     df=data,
...     conditions=["control", "treatment"],
...     selector_val="MCF10A"
... )
>>> # Triplicate stacked plot with boxes
>>> fig, ax = cellcycle_stacked(
...     df=data,
...     conditions=["control", "treatment"],
...     show_triplicates=True,
...     selector_val="MCF10A"
... )
>>> # Grouped stacked plot with custom phases
>>> fig, ax = cellcycle_stacked(
...     df=data,
...     conditions=["ctrl", "drug1", "drug2", "drug3"],
...     group_size=2,  # Group in pairs
...     cc_phases=True,  # Use cell cycle terminology
...     phase_order=["G1", "S", "G2/M"]  # Exclude Sub-G1 and Polyploid
... )
>>> # Plot without legend (for subplots or custom legends)
>>> fig, ax = cellcycle_stacked(
...     df=data,
...     conditions=["control", "treatment"],
...     show_legend=False
... )