API Reference

Plotting extension for PyMassSpec.

Functions:

plot_ic(ax, ic[, minutes])

Plots an Ion Chromatogram.

plot_mass_spec(ax, mass_spec, **kwargs)

Plots a Mass Spectrum.

plot_peaks(ax, peak_list[, label, style])

Plots the locations of peaks as found by PyMassSpec.

plot_head2tail(ax, top_mass_spec, …[, …])

Plots two mass spectra head to tail.

Classes:

ClickEventHandler(peak_list[, fig, ax, …])

Class to enable clicking of a chromatogram to view the intensities top n_intensities most intense ions at that peak, and viewing of the mass spectrum with a right click.

plot_ic(ax, ic, minutes=False, **kwargs)[source]

Plots an Ion Chromatogram.

Parameters
  • ax (Axes) – The axes to plot the IonChromatogram on.

  • ic (IonChromatogram) – Ion chromatogram m/z channels for plotting.

  • minutes (bool) – Whether the x-axis should be plotted in minutes. Default False (plotted in seconds)

Other Parameters

matplotlib.lines.Line2D properties. Used to specify properties like a line label (for auto legends), linewidth, antialiasing, marker face color.

>>> plot_ic(im.get_ic_at_index(5), label='IC @ Index 5', linewidth=2)

See matplotlib.lines.Line2D for the list of possible keyword arguments.

Return type

List[Line2D]

Returns

A list of Line2D objects representing the plotted data.

plot_mass_spec(ax, mass_spec, **kwargs)[source]

Plots a Mass Spectrum.

Parameters
Other Parameters

matplotlib.lines.Line2D properties. Used to specify properties like a line label (for auto legends), linewidth, antialiasing, marker face color.

Example:

>>> plot_mass_spec(im.get_ms_at_index(5), linewidth=2)
>>> ax.set_title(f"Mass spec for peak at time {im.get_time_at_index(5):5.2f}")

See matplotlib.lines.Line2D for the list of possible keyword arguments.

Return type

BarContainer

Returns

Container with all the bars, and optionally errorbars.

plot_peaks(ax, peak_list, label='Peaks', style='o')[source]

Plots the locations of peaks as found by PyMassSpec.

Parameters
  • ax (Axes) – The axes to plot the peaks on.

  • peak_list (Sequence[Peak]) – List of peaks to plot.

  • label (str) – label for plot legend. Default 'Peaks'.

  • style (str) – The marker style. See matplotlib.markers for a complete list. Default 'o'.

Return type

List[Line2D]

Returns

A list of Line2D objects representing the plotted data.

plot_head2tail(ax, top_mass_spec, bottom_mass_spec, top_spec_kwargs=None, bottom_spec_kwargs=None)[source]

Plots two mass spectra head to tail.

Parameters
  • ax (Axes) – The axes to plot the MassSpectra on.

  • top_mass_spec (MassSpectrum) – The mass spectrum to plot on top.

  • bottom_mass_spec (MassSpectrum) – The mass spectrum to plot on the bottom.

  • top_spec_kwargs (Optional[Mapping]) – A dictionary of keyword arguments for the top mass spectrum. Defaults to red with a line width of 0.5.

  • bottom_spec_kwargs (Optional[Mapping]) – A dictionary of keyword arguments for the bottom mass spectrum. Defaults to blue with a line width of 0.5.

top_spec_kwargs and bottom_spec_kwargs are used to specify properties like a line label (for auto legends), linewidth, antialiasing, and marker face color. See matplotlib.lines.Line2D for the list of possible keyword arguments.

Return type

Tuple[BarContainer, BarContainer]

Returns

A tuple of containers with all the bars, and optionally errorbars, for the top and bottom spectra.

class ClickEventHandler(peak_list, fig=None, ax=None, tolerance=0.005, n_intensities=5)[source]

Bases: object

Class to enable clicking of a chromatogram to view the intensities top n_intensities most intense ions at that peak, and viewing of the mass spectrum with a right click.

Parameters
  • peak_list (Sequence[Peak]) – The list of peaks identified in the chromatogram.

  • fig (Optional[Figure]) – The figure to associate the event handler with. Defaults to the current figure. (see plt.gcf().

  • ax (Optional[Axes]) – The axes to associate the event handler with. Defaults to the current axes. (see plt.gca().

  • tolerance (float) – Default 0.005.

  • n_intensities (int) – Default 5.

Attributes:

fig

The figure to associate the event handler with.

ax

The axes to associate the event handler with.

ms_fig

The figure to plot mass spectra on after right clicking the plot.

ms_ax

The axes to plot mass spectra on after right clicking the plot.

n_intensities

The number of top intensities to show in the terminal when left clicking the plot.

cid

The callback ID for the button press event.

Methods:

onclick(event)

Finds the n highest intensity m/z channels for the selected peak.

get_n_largest(intensity_list)

Computes the indices of the largest n ion intensities for writing to console.

fig

Type:    Figure

The figure to associate the event handler with.

ax

Type:    Axes

The axes to associate the event handler with.

ms_fig

Type:    Figure

The figure to plot mass spectra on after right clicking the plot.

ms_ax

Type:    Axes

The axes to plot mass spectra on after right clicking the plot.

n_intensities

Type:    int

The number of top intensities to show in the terminal when left clicking the plot.

cid

Type:    Optional[int]

The callback ID for the button press event.

onclick(event)[source]

Finds the n highest intensity m/z channels for the selected peak. The peak is selected by clicking on it. If a button other than the left one is clicked, a new plot of the mass spectrum is displayed.

Parameters

event (MouseEvent) – a mouse click by the user

get_n_largest(intensity_list)[source]

Computes the indices of the largest n ion intensities for writing to console.

Parameters

intensity_list (List[float]) – List of ion intensities.

Return type

List[int]

Returns

Indices of largest n_intensities ion intensities.

pymassspec_plot.utils

Utility functions.

Functions:

invert_mass_spec(mass_spec[, inplace])

Invert the mass spectrum for display in a head2tail plot.

invert_mass_spec(mass_spec, inplace=False)[source]

Invert the mass spectrum for display in a head2tail plot.

Parameters
Return type

MassSpectrum

Returns

The normalized mass spectrum.