API Reference¶
Plotting extension for PyMassSpec.
Functions:
|
Plots an Ion Chromatogram. |
|
Plots a Mass Spectrum. |
|
Plots the locations of peaks as found by PyMassSpec. |
|
Plots two mass spectra head to tail. |
Classes:
|
Class to enable clicking of a chromatogram to view the intensities top |
-
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. DefaultFalse
(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
- Returns
A list of Line2D objects representing the plotted data.
-
plot_mass_spec
(ax, mass_spec, **kwargs)[source]¶ Plots a Mass Spectrum.
- Parameters
ax (
Axes
) – The axes to plot theMassSpectrum
on.mass_spec (
MassSpectrum
) – The mass spectrum to plot.
- 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
- 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
- Return type
- 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 of0.5
.bottom_spec_kwargs (
Optional
[Mapping
]) – A dictionary of keyword arguments for the bottom mass spectrum. Defaults to blue with a line width of0.5
.
top_spec_kwargs
andbottom_spec_kwargs
are used to specify properties like a line label (for auto legends), linewidth, antialiasing, and marker face color. Seematplotlib.lines.Line2D
for the list of possible keyword arguments.- Return type
- 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. (seeplt.gcf()
.ax (
Optional
[Axes
]) – The axes to associate the event handler with. Defaults to the current axes. (seeplt.gca()
.tolerance (
float
) – Default0.005
.n_intensities (
int
) – Default5
.
Attributes:
The figure to associate the event handler with.
The axes to associate the event handler with.
The figure to plot mass spectra on after right clicking the plot.
The axes to plot mass spectra on after right clicking the plot.
The number of top intensities to show in the terminal when left clicking the plot.
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.
-
n_intensities
¶ Type:
int
The number of top intensities to show in the terminal when left clicking the plot.
-
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
pymassspec_plot.utils
¶
Utility functions.
Functions:
|
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
mass_spec (
MassSpectrum
) – The Mass Spectrum to normalizeinplace (
bool
) – Whether the inversion should be applied to theMassSpectrum
object given (True
), or to a copy (False
). DefaultFalse
.
- Return type
- Returns
The normalized mass spectrum.