.volcano_plot
- proteopy.utils.volcano_plot(fc_vals, pvals, fc_thresh=None, pval_thresh=None, *, labels=None, top_labels=None, highlight_labels=None, figsize=(6.0, 5.0), xlabel=None, ylabel=None, alt_color=None, yscale_log=True, title=None, show=True, save=None, ax=None)[source]
Volcano plot renderer (framework-agnostic).
Draws a scatter plot of fold change (x-axis) versus p-value (y-axis). Points are colored by significance or by an optional alternative boolean mask.
- Parameters:
fc_vals (Sequence[float] | np.ndarray) – Fold change values (x-axis).
pvals (Sequence[float] | np.ndarray) – P-values (y-axis). Must be same length as
fc_vals.fc_thresh (float | None, optional) – Absolute fold change threshold for significance. When
None, the fold change requirement for significance coloring is dropped. Threshold line is not drawn.pval_thresh (float | None, optional) – P-value threshold for significance. When
None, the p-value requirement for significance coloring is dropped. Threshold line is not drawn. When both thresholds areNone, all points are colored as significant (blue for negative FC, red for positive FC).labels (Sequence[str] | np.ndarray | None, optional) – Labels for each point, same length as
fc_vals. Required whentop_labelsis set.top_labels (int | None, optional) – Number of top proteins to label per side (up to 2N total). Ranked by smallest p-value, then largest
|fc|.highlight_labels (Sequence[str] | None, optional) – Sequence of label strings to highlight on the plot. Each entry must match a value in
labels. Matched points are annotated with their label and a connecting arrow. Labels not found after filtering trigger a warning.figsize (tuple[float, float], optional) – Figure dimensions (width, height) in inches.
xlabel (str | None, optional) – X-axis label. Defaults to
"logFC"whenNone.ylabel (str | None, optional) – Y-axis label. When
None, defaults to"pval"ifyscale_log=Trueor"-log10(pval)"ifyscale_log=False.alt_color (list[bool] | np.ndarray | None, optional) – Boolean mask (same length as
fc_vals) for alternative coloring.Trueentries are colored purple,Falsegray. Overrides significance-based coloring.yscale_log (bool, optional) – When
True, plot raw p-values on a log10-scaled inverted y-axis. WhenFalse, plot-log10(pval)on a linear y-axis.title (str | None, optional) – Plot title. If
None, no title is set.show (bool, optional) – Call
matplotlib.pyplot.show()to display the plot.save (str | Path | None, optional) – File path to save the figure at 300 DPI.
ax (matplotlib.axes.Axes | None, optional) – Matplotlib Axes to plot onto. If
None, a new figure and axes are created.
- Returns:
The Matplotlib Axes object used for plotting.
- Return type:
Axes
- Raises:
ValueError – If
fc_valsorpvalsare not 1D, contain non-numeric values, or have different lengths; if no valid data remains after filtering; iffc_threshis not positive (when set); ifpval_threshis not in[0, 1](when set); iftop_labelsis set butlabelsisNone, or is not a positive integer; ifhighlight_labelsis set butlabelsisNone, contains duplicates, or contains non-string values; if bothtop_labelsandhighlight_labelsare set; iflabelscontains non-string values; ifaxis not amatplotlib.axes.Axesobject (when set); ifalt_colorfails validation.
Examples
Basic usage with lists:
>>> from proteopy.utils.stat_tests import volcano_plot >>> fc = [-2.1, -0.5, 0.3, 1.8, 3.0] >>> pv = [0.001, 0.3, 0.5, 0.04, 0.0005] >>> volcano_plot(fc, pv, show=False) <Axes: ...>
With fold change and p-value thresholds:
>>> volcano_plot( ... fc, pv, ... fc_thresh=1.5, ... pval_thresh=0.05, ... show=False, ... ) <Axes: ...>
With
top_labelsto annotate the most significant hits:>>> genes = ["GeneA", "GeneB", "GeneC", "GeneD", "GeneE"] >>> volcano_plot( ... fc, pv, ... fc_thresh=1.5, ... pval_thresh=0.05, ... labels=genes, ... top_labels=2, ... show=False, ... ) <Axes: ...>
With
highlight_labelsto annotate specific proteins:>>> volcano_plot( ... fc, pv, ... labels=genes, ... highlight_labels=["GeneA", "GeneE"], ... show=False, ... ) <Axes: ...>