OpenMS / pyopenms-docs

pyOpenMS readthedocs documentation, additional utilities, addons, scripts, and examples.
https://pyopenms.readthedocs.io
Other
43 stars 50 forks source link

ImportError: cannot import name 'plotting' from 'pyopenms' #338

Closed phage-GP closed 1 year ago

phage-GP commented 1 year ago

Describe the problem you encountered

ImportError: cannot import name 'plotting' from 'pyopenms'

What should be happening

An error occurred when I tried to use 'plot_spectrum' function according to pyopenms document

https://pyopenms.readthedocs.io/en/latest/_autosummary/pyopenms.plotting.plot_spectrum.html#pyopenms.plotting.plot_spectrum

Screenshots

Here is my code:

from pyopenms import MSSpectrum
from pyopenms import plotting
import matplotlib.pyplot as plt
import pandas as pd

and error report message

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
Input In [39], in <cell line: 2>()
      1 from pyopenms import MSSpectrum
----> 2 from pyopenms import plotting
      3 import matplotlib.pyplot as plt
      4 import pandas as pd

ImportError: cannot import name 'plotting' from 'pyopenms' 

I want to know whether the API has changed.

phage-GP commented 1 year ago

After reviewing the source code, you can find that the relevant api has indeed changed.

Here is the source code file Anaconda\envs\xxx\Lib\site-packages\pyopenms\Plotting.py

def plotSpectrum(s):
    import pylab
    x, y = s.get_peaks()
    pylab.bar( x, y )
    pylab.xlabel("m/z")
    pylab.ylabel("Intensity")
    pylab.show()

So the modified code can run successfully,

from pyopenms.Plotting import plotSpectrum
jpfeuffer commented 1 year ago

Correct, the latest documentation refers to the nightly snapshots. In 2.8 it was still called Plotting.