plotSpectrum syntax mantidplot vs workbench?

I have a script with the following lines, that executes quite happily in mantidplot:

chiplot = plotSpectrum(source=[chi2vals],indices=[0],type = 0)

However, fails in workbench with the error:

plotSpectrum() got an unexpected keyword argument ‘source’

If I delete “source=”, then the code runs in both workbench and mantidplot.

Did the syntax change, or is this a bug? Thanks!

So plotSpectrum is tied to MantidPlot and a new version of plotSpectrum was made for Workbench. The inputs are very similar, but the first input for the new workbench version is workspaces, but this keyword is not callable. So the correct thing to do in Workbench is just input the workspace name as you did! :slight_smile:

For the correct inputs for MantidPlot see here: https://docs.mantidproject.org/nightly/api/python/mantidplot/plotSpectrum.html

For the correct inputs in workbench, you can look at code completion:

I hope this helps!

Hi Daniel, Thanks for the reply, yes it helps!

I also discovered another (possibly related) question. Back on Monday, I added some code you gave me to prevent the creation of a new plotting window if one exists already. The code was:

global PLOTTING_WINDOW_STAT
if PLOTTING_WINDOW_STAT is None or PLOTTING_WINDOW_STAT._getHeldObject() is None:
    PLOTTING_WINDOW_STAT = plotSpectrum(w,indices=[0],type = 0)
else:
    plotSpectrum(w,indices=[0],type = 0,window=PLOTTING_WINDOW_STAT,clearWindow=True)

This is giving me an error:

‘Figure’ object has no attribute ‘_getHeldObject’

Is this also a difference in how plotting is done in Workbench?

Thanks again!

p.s. I also implemented the GUI code you provided, it works nicely :smile:

Hi Malcolm,

As I have mentioned via email, the ._getHeldObject() method is related to the qt plotting in MantidPlot and is not required in Workbench.

So for Workbench this code can be simplified to:

global PLOTTING_WINDOW_STAT
if PLOTTING_WINDOW_STAT is None:
    PLOTTING_WINDOW_STAT = plotSpectrum(w,indices=[0],type = 0)
else:
    plotSpectrum(w,indices=[0],type = 0,window=PLOTTING_WINDOW_STAT,clearWindow=True)