6. Plotting functions

Plotting functions for pymzML

class plot.Factory(filename=None)

Class to plot pymzml.spec.Spectrum as svg/xhtml.

Parameters:filename (string) – Name for the output file. Default = “spectra.xhtml”

Example:

>>> import pymzml, get_example_file
>>> mzMLFile = 'profile-mass-spectrum.mzml'
>>> example_file = get_example_file.open_example(mzMLFile)
>>> run = pymzml.run.Run("../mzML_example_files/"+mzMLFile, precisionMSn = 250e-6)
>>> p = pymzml.plot.Factory()
>>> for spec in run:
>>>     p.newPlot()
>>>     p.add(spec.peaks, color=(200,00,00), style='circles')
>>>     p.add(spec.centroidedPeaks, color=(00,00,00), style='sticks')
>>>     p.add(spec.reprofiledPeaks, color=(00,255,00), style='circles')
>>>     p.save( filename="output/plotAspect.xhtml" , mzRange = [745.2,745.6] )
newPlot(header=None, mzRange=[None, None], normalize=False)

Add new plot to the plotFactory.

Parameters:
  • header (string) – an optional title that will be printed above the plot
  • mzRange (tuple of minMZ,maxMZ) – Boundaries of the new plot
  • normalize – whether or not the individal data sets are normalized in the plot
setAdditionalLegend(listOfStrings=None)

Add Legend to the plot.

Parameters:listOfStrings (list of string) – Extra Legend to the plot
add(data, color=(0, 0, 0), style='sticks', mzRange=[None, None], opacity=0.4)

Add data to the graph.

Parameters:
  • data (list of tuples (mz,i)) – The data added to the graph
  • color (tuple (R,G,B)) – color encoded in RGB. Default = (0,0,0)
  • style (string) – plotting style. Default = “circles”.
  • mzRange (tuple of minMZ,maxMZ) – Boundaries that should be added to the current plot
Currently supported styles are:
  • ‘emptycircles’
  • ‘circles’
  • ‘sticks’
  • ‘squares’
  • ‘area’
  • ‘triangle’
  • ‘label’

NOTE: The data format for label style is [( mz1, ‘label1’ ), ( mz2, ‘label2’ ), ( mz3, ‘label3’ ) ].

info()

Returns summary about the plotting factory, i.e.how many plots and how many datasets per plot.

save(filename=None, mzRange=[None, None], pureSvg=False)

Saves all plots and their data points that have been added to the plotFactory.

Parameters:
  • filename (string) – Name for the output file. Default = “spectra.xhtml”
  • mzRange (list) – m/z range which should be considered [start, end]. Default = [ None , None ]