# 6. Plotting functions

Plotting functions for pymzML. The Factory object can hold several plots with several data traces each. The plot will be rendered as interactive plotly plots.

class `plot.``Factory`(filename=None)

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

  Parameters: | filename (str) – 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='sticks')
      >>>     p.add(spec.centroided_peaks, color=(00,00,00), style='sticks')
      >>>     p.add(spec.reprofiled_peaks, color=(00,255,00), style='sticks')
      >>>     p.save( filename="output/plotAspect.xhtml" , mzRange = (745.2,745.6) )

  `newPlot`(header='', mzRange=None, normalize=False, precision='5e-6')

    Add new plot to the plotting Factory.

    Parameters: | header (str) – an optional title that will be printed above the plot mzRange (tuple) – Boundaries of the new plot normalize (boolean) – whether or not the individal data sets are normalized in the plot precision (float) – measuring precision used in handler. Default 5e-6.

  `add`(data, color=(0, 0, 0), style='sticks', mzRange=None, opacity=0.8, name=None, plotNum=-1)

    Add data to the graph.

    Parameters: | data (list) – The data added to the graph. Must be list of tuples, like (mz,i) or (mz1, mz2, i, string) style (str) – plotting style. Default = “sticks”. Currently supported styles are: ‘sticks’ ‘sticks.centroided’ ‘triangle’ (small, medium or big) ‘label.sticks’ ‘label.triangle’ (small, medium or big) ‘label.spline’ (top, medium or bottom) ‘label.linear’ (top, medium or bottom) color (tuple) – color encoded in RGB. Default = (0,0,0) mzRange (tuple) – Boundaries that should be added to the current plot opacity (float) – opacity of the data points name (str) – name of data in legend plotNum (int) – Add data to plot[plotNum]

  `info`()

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

  `save`(filename='spectra.xhtml', xLimits=None)

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

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

  `get_data`()

    Return data and layout in JSON format.

    Returns: | JSON compatible python dict
    Return type: | plots (dict)