3.4. Plotting functions

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 m/z or profile data using plotly (https://plot.ly/).

Parameters:filename (str) – Name for the output file. Default = “spectrum_plot.html”
add(data, color=(0, 0, 0), style='sticks', mz_range=None, int_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 with the following format. Note that i can be set to ‘max_intensity’ for setting the label position to the maximum intensity.

  • (mz,i) for all styles, except label,
  • (mz,i, string) for label.hoverinfo, .sticks and .triangle
  • (mz1, mz2, i, string) for label.linear and .spline

Keyword Arguments:
 
  • color (tuple) – color encoded in RGB. Default = (0,0,0)
  • style (str) –

    plotting style. Default = “sticks”. Currently supported styles are:

    • ’lines’: Datapoints connected by lines
    • ’points’: Datapoints without connection
    • ’sticks’: Vertical line at given m/z (corresponds to centroided peaks)
    • ’triangle’ (MS_precision, micro, tiny, small, medium, big): The top of the triangle corresponds to the given m/z, the width corresponds to he given format, e.g. ‘triangle.MS_precision’
    • ’label.hoverinfo’: Label string appears as plotly hover info
    • ’label.linear’ (top, medium or bottom)
    • ’label.spline’ (top, medium or bottom)
    • ’label.sticks’
    • ’label.triangle’ (small, medium or big)
  • mz_range (list) – Boundaries that should be added to the current plot
  • int_range (list) – 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

Note

The mz_range and int_range in the add() function sets the limits of datapoints added to the plot. This is in contrast to defining a range in the layout, which only defines the area that is depicted (i.e. the zoom) but still adds the datapoints to the plot (can be seen by zooming out).

get_data()[source]

Return data and layout in JSON format.

Returns:JSON compatible python dict
Return type:plots (dict)
info()[source]

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

newPlot(MS_precision='5e-6', title=None)[source]

Deprecated since version 1.2.

new_plot(MS_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.

Keyword Arguments:
 
  • title (str) – an optional title that will be printed above the plot
  • MS_precision (float) – measuring MS_precision used in handler. Default 5e-6.

Note

Old function newPlot() is still working. However, the new syntax should be used.

save(filename=None, mz_range=None, int_range=None, layout=None)[source]

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

Keyword Arguments:
 
  • filename (str) – Name for the output file. Default = “spectrum_plot.html”
  • mz_range (list) – m/z range which should be considered [start, end]. Default = None
  • int_range (list) – intensity range which should be considered [min, max]. Default = None
  • layout (dict) – dictionary containing layout information in plotly style

Note

mz_range and int_range defined here will be applied to all subplots in the current plot, i.e. ranges defined when adding a subplot will be overwritten. To avoid this, a list of lists can be given in the order corresponding to the subplots.