| 1 |
.. code-block:: python |
| 2 |
|
| 3 |
#!/usr/bin/env python |
| 4 |
# -*- coding: utf-8 -*- |
| 5 |
|
| 6 |
import os |
| 7 |
|
| 8 |
import pymzml |
| 9 |
|
| 10 |
|
| 11 |
def main(): |
| 12 |
""" |
| 13 |
This function shows how to plot a simple spectrum. It can be directly |
| 14 |
plotted via this script or using the python console. |
| 15 |
|
| 16 |
usage: |
| 17 |
|
| 18 |
./plot_spectrum.py |
| 19 |
|
| 20 |
""" |
| 21 |
|
| 22 |
example_file = os.path.join( |
| 23 |
os.path.dirname(__file__), os.pardir, "tests", "data", "example.mzML" |
| 24 |
) |
| 25 |
run = pymzml.run.Reader(example_file) |
| 26 |
p = pymzml.plot.Factory() |
| 27 |
for spec in run: |
| 28 |
p.new_plot() |
| 29 |
p.add(spec.peaks("centroided"), color=(0, 0, 0), style="sticks", name="peaks") |
| 30 |
filename = "example_plot_{0}_{1}.html".format( |
| 31 |
os.path.basename(example_file), spec.ID |
| 32 |
) |
| 33 |
p.save(filename=filename) |
| 34 |
print("Plotted file: {0}".format(filename)) |
| 35 |
break |
| 36 |
|
| 37 |
|
| 38 |
if __name__ == "__main__": |
| 39 |
main() |