mass-spectrometry-data-visualization-pandas
Summary
Visualize mass spectrometry data (spectra, chromatograms, mobilograms, peak maps) directly from Pandas DataFrames using pyOpenMS-Viz with support for multiple plotting backends (matplotlib, Bokeh, Plotly). This skill enables rapid prototyping and publication-ready rendering of 1D and 2D MS data across static and interactive output formats.
When to use
When you have mass spectrometry data (mzML, Bruker .d, or CSV) loaded into a Pandas DataFrame with columns for m/z, retention time, ion mobility, or intensity values, and you need to render spectrum plots, chromatograms, mobilograms, or 2D peak maps. Use this skill when you need to switch between static (matplotlib) and interactive (Bokeh, Plotly) backends, or when you want a consistent Pandas-native plotting API without learning multiple visualization libraries.
When NOT to use
- Input is not tabular or cannot be represented in a Pandas DataFrame (e.g., raw binary spectral data without parsing)
- You require real-time streaming visualization of live instrument data (pyOpenMS-Viz is designed for static/offline data)
- You need custom plot types not supported by the four core MS plot components (ChromatogramPlot, MobilogramPlot, SpectrumPlot, PeakMapPlot)
Inputs
- Pandas DataFrame with MS data columns (m/z, intensity, retention time, ion mobility)
- mzML files (via pymzml or pyOpenMS)
- Bruker .d format files (via AlphaTims)
- CSV files containing parsed MS data
Outputs
- Static matplotlib figure files (.png, .pdf, .svg)
- Interactive Bokeh HTML widgets and JSON representations
- Interactive Plotly HTML figures with hover tooltips and zooming
- Rendered spectrum plots, chromatogram plots, mobilogram plots, and 2D/3D peak map plots
How to apply
Load MS data into a Pandas DataFrame with appropriate column names (e.g., m/z, intensity, retention time, ion mobility). Call the DataFrame .plot() method, specifying the x, y (and optionally z for peakmap) column names, set the kind parameter to one of: 'spectrum', 'chromatogram', 'mobilogram', or 'peakmap', and set the backend to 'ms_matplotlib', 'ms_bokeh', or 'ms_plotly'. For spectrum plots, use m/z on x-axis and intensity on y-axis with SpectrumConfig parameters. For chromatogram/mobilogram plots, use retention time or ion mobility on x-axis and intensity on y-axis, optionally using the by parameter to separate multiple mass traces. For peakmap plots, use m/z on x-axis, retention time on y-axis, and intensity on z-axis (or color channel), optionally enabling add_marginals and plot_3d with PeakMapConfig parameters. Verify output by comparing generated figure file formats and visual structure against reference gallery examples from the pyOpenMS-Viz repository.
Related tools
- pyOpenMS-Viz (Primary visualization library providing Pandas DataFrame plotting interface for MS data) — https://github.com/OpenMS/pyopenms_viz
- Pandas (Data structure (DataFrame) that holds MS data and provides .plot() method extension)
- matplotlib (Backend for static figure rendering via ms_matplotlib backend parameter)
- Bokeh (Backend for interactive HTML widget rendering via ms_bokeh backend parameter)
- Plotly (Backend for interactive 3D and 2D figure rendering via ms_plotly backend parameter)
- pymzml (Optional upstream tool for parsing mzML files into Pandas DataFrames)
- pyOpenMS (Optional upstream tool for parsing mzML and MS data into Pandas DataFrames)
- AlphaTims (Optional upstream tool for parsing Bruker .d format files into Pandas DataFrames)
Examples
ms_data.plot(x="m/z", y="intensity", kind="spectrum", backend="ms_matplotlib")
Evaluation signals
- Generated figure files exist and match expected format (PNG/PDF/SVG for matplotlib, HTML for Bokeh/Plotly)
- Visual output structure is consistent with reference gallery outputs (gallery_scripts/ms_matplotlib/, ms_bokeh/, ms_plotly/)
- For spectrum plots: x-axis displays m/z range, y-axis displays intensity values with correct scale
- For chromatogram/mobilogram plots: x-axis displays retention time or ion mobility, y-axis shows intensity, optional mass traces are visually separated
- For peakmap plots: x-axis shows m/z, y-axis shows retention time, color intensity or z-axis represents signal intensity; optional 3D rendering renders correctly in Plotly backend only
- Interactive backends (Bokeh, Plotly) enable zoom, pan, and hover tooltips; static matplotlib output is non-interactive
Limitations
- PeakMap 3D plots are only supported in matplotlib and Plotly backends, not in Bokeh
- The library requires data to be pre-loaded into a Pandas DataFrame with correctly named columns; it does not perform peak detection or data preprocessing
- Backend rendering performance may degrade with very large datasets (millions of data points); downsampling or filtering before visualization may be necessary
- Consistent API across backends means some advanced backend-specific features (e.g., WebGL rendering in Plotly) may not be exposed through the unified interface
Evidence
- [readme] pyOpenMS-Viz is a Python library that provides a simple interface for extending the plotting capabilities of Pandas DataFrames for creating static or interactive visualizations of mass spectrometry data.: "pyOpenMS-Viz is a Python library that provides a simple interface for extending the plotting capabilities of Pandas DataFrames for creating static or interactive visualizations of mass spectrometry"
- [readme] It integrates seamlessly with various plotting library backends (matpotlib, bokeh and plotly) and leverages the power of Pandas for data manipulation and representation.: "It integrates seamlessly with various plotting library backends (matpotlib, bokeh and plotly) and leverages the power of Pandas for data manipulation and representation."
- [other] For each of the four plot kinds (spectrum, chromatogram, mobilogram, peakmap), call the DataFrame .plot() method with the appropriate x, y (and z for peakmap) column names, set kind parameter to the plot type, and set backend to ms_matplotlib, ms_bokeh, or ms_plotly sequentially.: "For each of the four plot kinds (spectrum, chromatogram, mobilogram, peakmap), call the DataFrame .plot() method with the appropriate x, y (and z for peakmap) column names, set kind parameter to the"
- [readme] Support for multiple plotting backends: matplotlib (static), bokeh and plotly (interactive): "Support for multiple plotting backends: matplotlib (static), bokeh and plotly (interactive)"
- [other] Load example mass spectrometry data from publicly available sources (mzML files via pymzml/pyOpenMS, or Bruker .d format via AlphaTims) into a pandas DataFrame.: "Load example mass spectrometry data from publicly available sources (mzML files via pymzml/pyOpenMS, or Bruker .d format via AlphaTims) into a pandas DataFrame."
- [readme] PeakMap 3D | x, y, z | peakmap (plot3d=True) | ✓ | | ✓: "PeakMap 3D | x, y, z | peakmap (plot3d=True) | ✓ | | ✓"
1---2name: mass-spectrometry-data-visualization-pandas3description: Use when when you have mass spectrometry data (mzML, Bruker .d, or CSV) loaded into a Pandas DataFrame with columns for m/z, retention time, ion mobility, or intensity values, and you need to render spectrum plots, chromatograms, mobilograms, or 2D peak maps.4license: CC-BY-4.05---67# mass-spectrometry-data-visualization-pandas89## Summary1011Visualize mass spectrometry data (spectra, chromatograms, mobilograms, peak maps) directly from Pandas DataFrames using pyOpenMS-Viz with support for multiple plotting backends (matplotlib, Bokeh, Plotly). This skill enables rapid prototyping and publication-ready rendering of 1D and 2D MS data across static and interactive output formats.1213## When to use1415When you have mass spectrometry data (mzML, Bruker .d, or CSV) loaded into a Pandas DataFrame with columns for m/z, retention time, ion mobility, or intensity values, and you need to render spectrum plots, chromatograms, mobilograms, or 2D peak maps. Use this skill when you need to switch between static (matplotlib) and interactive (Bokeh, Plotly) backends, or when you want a consistent Pandas-native plotting API without learning multiple visualization libraries.1617## When NOT to use1819- Input is not tabular or cannot be represented in a Pandas DataFrame (e.g., raw binary spectral data without parsing)20- You require real-time streaming visualization of live instrument data (pyOpenMS-Viz is designed for static/offline data)21- You need custom plot types not supported by the four core MS plot components (ChromatogramPlot, MobilogramPlot, SpectrumPlot, PeakMapPlot)2223## Inputs2425- Pandas DataFrame with MS data columns (m/z, intensity, retention time, ion mobility)26- mzML files (via pymzml or pyOpenMS)27- Bruker .d format files (via AlphaTims)28- CSV files containing parsed MS data2930## Outputs3132- Static matplotlib figure files (.png, .pdf, .svg)33- Interactive Bokeh HTML widgets and JSON representations34- Interactive Plotly HTML figures with hover tooltips and zooming35- Rendered spectrum plots, chromatogram plots, mobilogram plots, and 2D/3D peak map plots3637## How to apply3839Load MS data into a Pandas DataFrame with appropriate column names (e.g., m/z, intensity, retention time, ion mobility). Call the DataFrame `.plot()` method, specifying the x, y (and optionally z for peakmap) column names, set the `kind` parameter to one of: 'spectrum', 'chromatogram', 'mobilogram', or 'peakmap', and set the `backend` to 'ms_matplotlib', 'ms_bokeh', or 'ms_plotly'. For spectrum plots, use m/z on x-axis and intensity on y-axis with SpectrumConfig parameters. For chromatogram/mobilogram plots, use retention time or ion mobility on x-axis and intensity on y-axis, optionally using the `by` parameter to separate multiple mass traces. For peakmap plots, use m/z on x-axis, retention time on y-axis, and intensity on z-axis (or color channel), optionally enabling `add_marginals` and `plot_3d` with PeakMapConfig parameters. Verify output by comparing generated figure file formats and visual structure against reference gallery examples from the pyOpenMS-Viz repository.4041## Related tools4243- **pyOpenMS-Viz** (Primary visualization library providing Pandas DataFrame plotting interface for MS data) — https://github.com/OpenMS/pyopenms_viz44- **Pandas** (Data structure (DataFrame) that holds MS data and provides .plot() method extension)45- **matplotlib** (Backend for static figure rendering via ms_matplotlib backend parameter)46- **Bokeh** (Backend for interactive HTML widget rendering via ms_bokeh backend parameter)47- **Plotly** (Backend for interactive 3D and 2D figure rendering via ms_plotly backend parameter)48- **pymzml** (Optional upstream tool for parsing mzML files into Pandas DataFrames)49- **pyOpenMS** (Optional upstream tool for parsing mzML and MS data into Pandas DataFrames)50- **AlphaTims** (Optional upstream tool for parsing Bruker .d format files into Pandas DataFrames)5152## Examples5354```55ms_data.plot(x="m/z", y="intensity", kind="spectrum", backend="ms_matplotlib")56```5758## Evaluation signals5960- Generated figure files exist and match expected format (PNG/PDF/SVG for matplotlib, HTML for Bokeh/Plotly)61- Visual output structure is consistent with reference gallery outputs (gallery_scripts/ms_matplotlib/, ms_bokeh/, ms_plotly/)62- For spectrum plots: x-axis displays m/z range, y-axis displays intensity values with correct scale63- For chromatogram/mobilogram plots: x-axis displays retention time or ion mobility, y-axis shows intensity, optional mass traces are visually separated64- For peakmap plots: x-axis shows m/z, y-axis shows retention time, color intensity or z-axis represents signal intensity; optional 3D rendering renders correctly in Plotly backend only65- Interactive backends (Bokeh, Plotly) enable zoom, pan, and hover tooltips; static matplotlib output is non-interactive6667## Limitations6869- PeakMap 3D plots are only supported in matplotlib and Plotly backends, not in Bokeh70- The library requires data to be pre-loaded into a Pandas DataFrame with correctly named columns; it does not perform peak detection or data preprocessing71- Backend rendering performance may degrade with very large datasets (millions of data points); downsampling or filtering before visualization may be necessary72- Consistent API across backends means some advanced backend-specific features (e.g., WebGL rendering in Plotly) may not be exposed through the unified interface7374## Evidence7576- [readme] pyOpenMS-Viz is a Python library that provides a simple interface for extending the plotting capabilities of Pandas DataFrames for creating static or interactive visualizations of mass spectrometry data.: "pyOpenMS-Viz is a Python library that provides a simple interface for extending the plotting capabilities of Pandas DataFrames for creating static or interactive visualizations of mass spectrometry"77- [readme] It integrates seamlessly with various plotting library backends (matpotlib, bokeh and plotly) and leverages the power of Pandas for data manipulation and representation.: "It integrates seamlessly with various plotting library backends (matpotlib, bokeh and plotly) and leverages the power of Pandas for data manipulation and representation."78- [other] For each of the four plot kinds (spectrum, chromatogram, mobilogram, peakmap), call the DataFrame .plot() method with the appropriate x, y (and z for peakmap) column names, set kind parameter to the plot type, and set backend to ms_matplotlib, ms_bokeh, or ms_plotly sequentially.: "For each of the four plot kinds (spectrum, chromatogram, mobilogram, peakmap), call the DataFrame .plot() method with the appropriate x, y (and z for peakmap) column names, set kind parameter to the"79- [readme] Support for multiple plotting backends: matplotlib (static), bokeh and plotly (interactive): "Support for multiple plotting backends: matplotlib (static), bokeh and plotly (interactive)"80- [other] Load example mass spectrometry data from publicly available sources (mzML files via pymzml/pyOpenMS, or Bruker .d format via AlphaTims) into a pandas DataFrame.: "Load example mass spectrometry data from publicly available sources (mzML files via pymzml/pyOpenMS, or Bruker .d format via AlphaTims) into a pandas DataFrame."81- [readme] PeakMap 3D | x, y, z | peakmap (plot3d=True) | ✓ | | ✓: "PeakMap 3D | x, y, z | peakmap (plot3d=True) | ✓ | | ✓"