pyms.Display
¶
Class to Display Ion Chromatograms and TIC.
Classes:
|
Class to enable clicking of chromatogram to view the intensities top n most intense ions at that peak, and viewing of the mass spectrum with a right click |
|
Class to display Ion Chromatograms and Total Ion Chromatograms from |
Functions:
|
Invert the mass spectrum for display in a head2tail plot. |
|
Plots two mass spectra head to tail. |
|
Plots an Ion Chromatogram. |
|
Plots a Mass Spectrum. |
|
Plots the locations of peaks as found by PyMassSpec. |
-
class
ClickEventHandler
(peak_list, fig=None, ax=None, tolerance=0.005, n_intensities=5)[source]¶ Bases:
object
Class to enable clicking of chromatogram to view the intensities top n most intense ions at that peak, and viewing of the mass spectrum with a right click
Methods:
get_n_largest
(intensity_list)Computes the indices of the largest n ion intensities for writing to console.
onclick
(event)Finds the n highest intensity m/z channels for the selected peak.
-
class
Display
(fig=None, ax=None)[source]¶ Bases:
object
Class to display Ion Chromatograms and Total Ion Chromatograms from
pyms.IonChromatogram.IonChromatogram
usingmatplotlib.pyplot
.- Parameters:
If
fig
is not given thenfig
andax
default to:>>> fig = plt.figure() >>> ax = fig.add_subplot(111)
If only
fig
is given thenax
defaults to:>>> ax = fig.add_subplot(111)
- Author:
Sean O’Callaghan
- Author:
Vladimir Likic
- Author:
Dominic Davis-Foster
Methods:
do_plotting
([plot_label])Plots TIC and IC(s) if they have been created by
plot_tic()
orplot_ic()
.get_5_largest
(intensity_list)Returns the indices of the 5 largest ion intensities.
onclick
(event)Finds the 5 highest intensity m/z channels for the selected peak.
plot_ic
(ic, **kwargs)Plots an Ion Chromatogram.
plot_mass_spec
(mass_spec, **kwargs)Plots a Mass Spectrum.
plot_peaks
(peak_list[, label])Plots the locations of peaks as found by PyMassSpec.
plot_tic
(tic[, minutes])Plots a Total Ion Chromatogram.
save_chart
(filepath[, filetypes])Save the chart to the given path with the given filetypes.
Show the chart on screen.
-
do_plotting
(plot_label=None)[source]¶ Plots TIC and IC(s) if they have been created by
plot_tic()
orplot_ic()
.Also adds detected peaks if they have been added by
plot_peaks()
-
onclick
(event)[source]¶ Finds the 5 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 – a mouse click by the user
-
plot_ic
(ic, **kwargs)[source]¶ Plots an Ion Chromatogram.
- Parameters:
ic (
IonChromatogram
) – Ion Chromatograms m/z channels for plotting- Other Parameters:
matplotlib.lines.Line2D
properties. Used to specify properties like a line label (for auto legends), linewidth, antialiasing, marker face color.Example:
>>> plot_ic(im.get_ic_at_index(5), label='IC @ Index 5', linewidth=2)
See https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.lines.Line2D.html for the list of possible kwargs
- Return type:
-
plot_mass_spec
(mass_spec, **kwargs)[source]¶ Plots a Mass Spectrum.
- Parameters:
mass_spec (
MassSpectrum
) – The mass spectrum at a given time/index- 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 https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.lines.Line2D.html for the list of possible kwargs
- Return type:
-
plot_tic
(tic, minutes=False, **kwargs)[source]¶ Plots a Total Ion Chromatogram.
- Parameters:
tic (
IonChromatogram
) – Total Ion Chromatogram.minutes (
bool
) – Whether to show the time in minutes. DefaultFalse
.
- Other Parameters:
matplotlib.lines.Line2D
properties. Used to specify properties like a line label (for auto legends), linewidth, antialiasing, marker face color.Example:
>>> plot_tic(data.tic, label='TIC', linewidth=2)
See https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.lines.Line2D.html for the list of possible kwargs
- Return type:
-
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, or to a copy (default behaviour). DefaultFalse
.
- Return type:
- Returns:
The normalized mass spectrum
-
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 ontop_mass_spec (
MassSpectrum
) – The Mass Spectrum to plot on topbottom_mass_spec (
MassSpectrum
) – The Mass Spectrum to plot on the bottomtop_spec_kwargs (
Optional
[Dict
]) – A dictionary of keyword arguments for the top mass spectrum. Defaults to red with a line width of 0.5bottom_spec_kwargs (
Optional
[Dict
]) – 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, marker face color.
See https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.lines.Line2D.html for the list of possible kwargs
- Returns:
A tuple of container with all the bars and optionally errorbars for the top and bottom spectra.
- Return type:
tuple of
matplotlib.container.BarContainer
-
plot_ic
(ax, ic, minutes=False, **kwargs)[source]¶ Plots an Ion Chromatogram.
- Parameters:
ax (
Axes
) – The axes to plot the IonChromatogram onic (
IonChromatogram
) – Ion Chromatograms m/z channels for plottingminutes (
bool
) – Whether the x-axis should be plotted in minutes. Default False (plotted in seconds). DefaultFalse
.
- Other Parameters:
matplotlib.lines.Line2D
properties. Used to specify properties like a line label (for auto legends), linewidth, antialiasing, marker face color.Example:
>>> plot_ic(im.get_ic_at_index(5), label='IC @ Index 5', linewidth=2)
See https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.lines.Line2D.html for the list of possible kwargs
- 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 the MassSpectrum onmass_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 https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.lines.Line2D.html for the list of possible kwargs
- Returns:
Container with all the bars and optionally errorbars.
- Return type: