3.3. Plotting funcions¶
Plotting functions for pymzML. The Factory object can hold several plots with several data traces each. The data can be visualized as an interactive plotly plot or be exported as JSON.
-
class
pymzml.plot.Factory(filename=None)[source]¶ -
__init__(filename=None)[source]¶ Interface to visualize mz or profile data using plotly.
Parameters: filename (str) – Name for the output file. Default = “spectrum_plot.html”
-
add(data, color=(0, 0, 0), style='sticks', mz_range=None, opacity=0.8, dash='solid', name=None, plot_num=-1, title=None)[source]¶ 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)
- color (tuple) – color encoded in RGB. Default = (0,0,0)
- style (str) –
plotting style. Default = “sticks”.
Currently supported styles are:
- ‘sticks’
- ‘triangle’ (small, medium or big)
- ‘lines’
- ‘points’
- ‘label.sticks’
- ‘label.triangle’ (small, medium or big)
- ‘label.spline’ (top, medium or bottom)
- ‘label.linear’ (top, medium or bottom)
- ‘label.lines’ (top, medium or bottom)
- mz_range (tuple) – Boundaries that should be added to the current plot
- opacity (float) – opacity of the data points
- dash (str) – type of line (‘solid’, ‘dash’, ‘longdash’, ‘dot’, ‘dashdot’, ‘longdashdot’)
- name (str) – name of data in legend
- plot_num (int) – Add data to plot[plot_num]
- title (str) – an optional title that will be printed above the plot
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.new_plot() >>> 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') >>> # add annotation 'My Annotation' at mz 100 >>> p.add([100, None, None, 'My Annotation'], style='label.triangle') >>> p.save( ... filename="output/plotAspect.xhtml", ... mz_range = (50.2,745.6) ... )
-
get_data()[source]¶ Return data and layout in JSON format.
Returns: plots – JSON compatible python dict Return type: dict
-
info()[source]¶ Prints summary about the plotting factory, i.e.how many plots and how many datasets per plot.
-
new_plot(precision='5e-6', title=None)[source]¶ Add new plot to the plotting Factory. Every plot will be put into the x * 2 grid of one single figure.
Parameters: - title (str) – an optional title that will be printed above the plot
- precision (float) – measuring precision used in handler. Default 5e-6.
-
save(filename=None, mz_range=None, layout=None)[source]¶ Saves all plots and their data points that have been added to the plotFactory.
Args: filename (str): Name for the output file. Default = “spectrum_plot.html” mz_range (tuple): m/z range which should be considered [start, end].
Default = Nonelayout (dict): dictionary containing layout information in plotly style
-