goatpy.plotting

Functions

check_batch(sdata[, table_name, batch_col, show])

plot_spectrum(, spectrum_color, peak_color, ...)

Plot the binned spectrum from a SpatialData object, with optional overlay

plot_spectra_comparison(, show, save_path, ...)

Overlay spectra from multiple pixels on a single axes.

Module Contents

goatpy.plotting.check_batch(sdata, table_name: str = 'maldi_adata', batch_col: str = 'batch', show: bool = True)[source]
goatpy.plotting.plot_spectrum(sdata: spatialdata.SpatialData, peaks_csv: str | pathlib.Path | None = None, mz_col: str | None = None, label_col: str | None = None, table_name: str = 'maldi_adata', pixel_index: int | None = None, reduce: str = 'mean', mz_range: Tuple[float, float] | None = None, tolerance: float = 0.1, label_top_n: int = 20, label_min_intensity_pct: float = 5.0, figsize: Tuple[float, float] = (14, 5), spectrum_color: str = '#3a6fa8', peak_color: str = '#d9534f', peak_linewidth: float = 1.2, spectrum_linewidth: float = 0.8, ax: matplotlib.pyplot.Axes | None = None, title: str | None = None, show: bool = True, save_path: str | pathlib.Path | None = None) matplotlib.pyplot.Axes[source]

Plot the binned spectrum from a SpatialData object, with optional overlay of a curated peak list CSV.

Parameters:
  • sdata (SpatialData) – Output of bin_imzml, bin_and_align, or load_and_align.

  • peaks_csv (str or Path, optional) – Path to a CSV file with curated peak m/z values (PEAKS.csv format or glycan_list.csv format). When supplied, each curated peak is marked on the spectrum with a vertical dashed line.

  • mz_col (str, optional) – Column name for m/z values in peaks_csv. Auto-detected when None.

  • label_col (str, optional) – Column name for peak labels in peaks_csv (e.g. “Composition”). Labels are drawn above the highest-intensity annotated peaks.

  • table_name (str, default "maldi_adata") – Table to read from sdata.tables.

  • pixel_index (int, optional) – Plot a single pixel’s spectrum. Plots the mean across all pixels when None.

  • reduce ("mean" | "median" | "max" | "sum", default "mean") – Reduction applied across all pixels when pixel_index is None.

  • mz_range ((lo, hi), optional) – Restrict the x-axis to this m/z window.

  • tolerance (float, default 0.1) – m/z tolerance (Da) used to match curated peaks to binned bin centres. A curated peak at 1257.5 Da will be matched if a bin centre lies within ±``tolerance`` Da.

  • label_top_n (int, default 20) – Maximum number of peak labels drawn (to avoid overlap). The highest-intensity matched peaks are labelled first.

  • label_min_intensity_pct (float, default 5.0) – Only draw a label if the matched bin’s intensity is ≥ this percentage of the maximum spectrum intensity.

  • figsize ((width, height), default (14, 5))

  • spectrum_color (str, default "#3a6fa8") – Line colour for the binned spectrum.

  • peak_color (str, default "#d9534f") – Colour for curated peak overlay lines and labels.

  • peak_linewidth (float, default 1.2)

  • spectrum_linewidth (float, default 0.8)

  • ax (matplotlib Axes, optional) – Plot into an existing Axes. A new figure is created when None.

  • title (str, optional) – Axes title. Auto-generated when None.

  • show (bool, default True) – Call plt.show() at the end.

  • save_path (str or Path, optional) – If supplied, save the figure to this path before showing.

Returns:

ax

Return type:

matplotlib Axes

Examples

>>> plot_spectrum(sdata)
>>> plot_spectrum(sdata, peaks_csv="goatpy/data/PEAKS.csv",
...              mz_range=(900, 2000))
>>> plot_spectrum(sdata, peaks_csv="goatpy/data/glycan_list.csv",
...              mz_col="Theoretical m/z [M+Na]",
...              label_col="Composition",
...              label_top_n=30)
>>> ax = plot_spectrum(sdata, show=False)   # embed in larger figure
goatpy.plotting.plot_spectra_comparison(sdata: spatialdata.SpatialData, pixel_indices: list[int], peaks_csv: str | pathlib.Path | None = None, mz_col: str | None = None, label_col: str | None = None, table_name: str = 'maldi_adata', mz_range: Tuple[float, float] | None = None, tolerance: float = 0.1, label_top_n: int = 15, figsize: Tuple[float, float] = (14, 5), show: bool = True, save_path: str | pathlib.Path | None = None) matplotlib.pyplot.Axes[source]

Overlay spectra from multiple pixels on a single axes.

Parameters:
  • sdata (SpatialData)

  • pixel_indices (list of int) – Row indices to overlay.

  • peaks_csv

  • mz_col

  • label_col

  • table_name

  • mz_range

:param : :param tolerance: :type tolerance: same as plot_spectrum :param label_top_n: :type label_top_n: same as plot_spectrum :param figsize: :type figsize: same as plot_spectrum :param show: :type show: same as plot_spectrum :param save_path: :type save_path: same as plot_spectrum

Returns:

ax

Return type:

matplotlib Axes