# Combined plots

<style>
/* Scientific figures are line art on a transparent background: black text
   disappears on a dark page. Rather than maintaining a second set of dark
   figures, render them on a light card in both themes, so the published
   colours stay exactly as they appear in the paper. */
.fig-card {
  background: #ffffff;
  border: 1px solid rgba(0, 0, 0, 0.10);
  border-radius: 10px;
  padding: 1.25rem 1.25rem 0.5rem;
  margin: 1.75rem 0;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}
.fig-card img { display: block; margin: 0 auto; max-width: 100%; height: auto; }
.fig-card figure { margin: 0; }
.fig-card figcaption {
  color: #3a3a3a;
  font-size: 0.86rem;
  line-height: 1.45;
  padding-top: 0.75rem;
}
</style>

The combined plot module provides two specialized multi-panel visualizations that integrate histograms, scatter plots, and statistical summaries for comprehensive data analysis.

See the [API reference](../reference/index.md) for full signatures and parameter documentation.


# Overview

The combplot module offers two distinct visualization approaches:

**combplot_feature**: Creates a vertically stacked grid layout for feature analysis. The number of rows grows with the number of features supplied (`2 + n_features` rows):

- Top row: DNA content histograms
- Second row: DNA vs EdU scatter plots with cell cycle phases
- One additional row per feature: DNA vs feature scatter plots with optional threshold coloring

Passing a single `feature` string reproduces the classic three-row layout (histogram → EdU → feature). Passing a list of features stacks one scatter row per feature underneath the EdU row, sharing the DNA-content x-axis.

**combplot_cellcycle**: Creates a 2-row grid with integrated barplot

- Top row: DNA content histograms
- Bottom row: DNA vs EdU scatter plots
- Right column: Stacked cell cycle phase barplot


# Examples


## Feature Analysis with Threshold

Analyze p21 intensity across conditions with threshold-based coloring:

``` python
from omero_screen_plots import combplot_feature
import pandas as pd

df = pd.read_csv("data.csv")
fig, axes = combplot_feature(
    df=df,
    conditions=['control', 'cond01', 'cond02', 'cond03'],
    feature="intensity_mean_p21_nucleus",
    threshold=5000,
    selector_col="cell_line",
    selector_val="MCF10A",
    title="p21 Intensity Analysis",
    cell_number=3000,
    save=True,
    file_format="svg"
)
```


<figure class="figure">
<p><img src="../assets/combplot_feature_p21.svg" class="img-fluid figure-img" /></p>
<figcaption>Feature Analysis with Threshold</figcaption>
</figure>


## Cell Area Analysis

Examine cell size distributions with DNA content context:

``` python
fig, axes = combplot_feature(
    df=df,
    conditions=['control', 'cond01', 'cond02'],
    feature="area_cell",
    threshold=2000,
    selector_col="cell_line",
    selector_val="MCF10A",
    title="Cell Area Analysis",
    cell_number=2000,
    fig_size=(8, 7)
)
```


<figure class="figure">
<p><img src="../assets/combplot_feature_area.svg" class="img-fluid figure-img" /></p>
<figcaption>Cell Area Analysis</figcaption>
</figure>


## Compact Feature Comparison

Compare control vs treatment with nuclear intensity:

``` python
fig, axes = combplot_feature(
    df=df,
    conditions=['control', 'cond01'],
    feature="intensity_mean_nucleus",
    threshold=7500,
    selector_val="MCF10A",
    title="Nuclear Intensity Comparison",
    cell_number=3000,
    fig_size=(6, 7)
)
```


<figure class="figure">
<p><img src="../assets/combplot_feature_nucleus.svg" class="img-fluid figure-img" /></p>
<figcaption>Compact Feature Comparison</figcaption>
</figure>


## Stacked Multi-Feature Analysis

Pass a **list** of features to stack one scatter row per feature beneath the EdU row. The grid height grows automatically, and each feature can take its own threshold (use `None` to disable colouring for a given row):

``` python
fig, axes = combplot_feature(
    df=df,
    conditions=['control', 'cond01', 'cond02', 'cond03'],
    feature=[
        "intensity_mean_p21_nucleus",
        "area_cell",
    ],
    threshold=[5000, None],   # one threshold per feature; None disables it
    selector_col="cell_line",
    selector_val="MCF10A",
    title="Stacked feature analysis",
    cell_number=2000,
    save=True,
    file_format="svg",
)
```

A scalar `threshold` (or `threshold=None`) is broadcast to every feature row, so `threshold=None` plots all feature rows in a single colour. When `fig_size` is left as `None` the figure height scales with the number of rows (matching the classic `(10, 7)` default for a single feature).


<figure class="figure">
<p><img src="../assets/combplot_feature_stacked.svg" class="img-fluid figure-img" /></p>
<figcaption>Stacked Multi-Feature Analysis</figcaption>
</figure>


## Cell Cycle Distribution Analysis

Comprehensive cell cycle analysis with integrated barplot:

``` python
from omero_screen_plots import combplot_cellcycle

fig, axes = combplot_cellcycle(
    df=df,
    conditions=['control', 'cond01', 'cond02', 'cond03'],
    selector_val="MCF10A",
    title="Cell Cycle Distribution",
    cell_number=3000,
    cc_phases=True,
    show_error_bars=True,
    save=True
)
```


<figure class="figure">
<p><img src="../assets/combplot_cellcycle_default.svg" class="img-fluid figure-img" /></p>
<figcaption>Cell Cycle Distribution Analysis</figcaption>
</figure>


## DNA Content Terminology

Use DNA content labels without error bars:

``` python
fig, axes = combplot_cellcycle(
    df=df,
    conditions=['control', 'cond01', 'cond02', 'cond03'],
    selector_val="MCF10A",
    title="DNA Content Analysis",
    cc_phases=False,  # Use <2N, 2N, S, 4N, >4N
    show_error_bars=False,
    fig_size=(12, 7)
)
```


<figure class="figure">
<p><img src="../assets/combplot_cellcycle_dna.svg" class="img-fluid figure-img" /></p>
<figcaption>DNA Content Terminology</figcaption>
</figure>


## Compact Cell Cycle View

Reduced conditions for space-efficient visualization:

``` python
fig, axes = combplot_cellcycle(
    df=df,
    conditions=['control', 'cond01', 'cond02'],
    selector_val="MCF10A",
    title="Compact Cell Cycle",
    cell_number=2000,
    fig_size=(10, 7)
)
```


<figure class="figure">
<p><img src="../assets/combplot_cellcycle_compact.svg" class="img-fluid figure-img" /></p>
<figcaption>Compact Cell Cycle View</figcaption>
</figure>


# Advanced Usage


## Data Sampling Control

The `cell_number` parameter controls sampling for scatter plots only:

``` python
# Histograms use full data, scatter plots sample 5000 cells
fig, axes = combplot_feature(
    df=df,
    conditions=conditions,
    feature="intensity_mean_p21_nucleus",
    threshold=5000,
    cell_number=5000,  # Only affects scatter plots
    selector_val="MCF10A"
)
```


## Multiple Feature Comparison

Stack several features in a single figure by passing aligned lists of features and thresholds. Each feature becomes its own scatter row underneath the shared EdU row:

``` python
fig, axes = combplot_feature(
    df=df,
    conditions=['control', 'treatment'],
    feature=["intensity_mean_p21_nucleus", "area_nucleus"],
    threshold=[5000, 500],   # aligned with `feature`; lengths must match
    selector_val="MCF10A",
    title="Multi-feature comparison",
)
```

If you would rather produce one figure per feature (for example to save them as separate files), loop over the features and call [combplot_feature](../reference/combplot_feature.md#omero_screen_plots.combplot_feature) with a single feature each time:

``` python
features = [
    ("intensity_mean_p21_nucleus", 5000),
    ("area_nucleus", 500),
]

for feature, threshold in features:
    fig, axes = combplot_feature(
        df=df,
        conditions=['control', 'treatment'],
        feature=feature,
        threshold=threshold,
        selector_val="MCF10A",
        title=f"{feature} Analysis",
        fig_size=(6, 7),
    )
```


## Custom Error Bar Control

Toggle error bars on cell cycle barplot:

``` python
# Without error bars for cleaner visualization
fig, axes = combplot_cellcycle(
    df=df,
    conditions=conditions,
    selector_val="MCF10A",
    show_error_bars=False,
    cc_phases=True
)
```


# See Also

- [`histogram_plot`](histogramplot.md) : Individual histogram plots
- [`scatter_plot`](scatterplot.md) : Individual scatter plots
- [`cellcycle_stacked`](cellcyclestacked.md) : Standalone cell cycle barplots
- [`feature_plot`](featureplot.md) : Feature comparison plots
