Two Y axes on a plot

In Workbench, plotting spectra with the GUI, is there any way to get two Y axes (left and right) and assign curves to them? I want to overplot spectra which have different Y scales/units and a common X scale. In this case they’re from different workspaces. The settings dialog seems to have provision for adjusting more than one axis set if it was to exist.

Hi,

Solely in the GUI there isn’t a way to do this! Out of interest, what are your Y units (are they the same?)

Here’s a short script that somewhat does what you want!

from mantid.simpleapi import *
import matplotlib.pyplot as plt
import numpy as np

GEM38370_Focussed = Load(Filename='C:/MantidInstall/TrainingCourseData/TrainingCourseData/GEM38370_Focussed.nxs', OutputWorkspace='GEM38370_Focussed')
D33 = Load(Filename='C:/MantidInstall/TrainingCourseData/TrainingCourseData/D33041421_tof.nxs', OutputWorkspace='D33')

# Create our first Axes object and plot a spectrum
fig, ax1 = plt.subplots(figsize=[10.447, 4.7766], subplot_kw={'projection': 'mantid'})
ax1.plot(D33, specNum=5)
ax1.set_ylabel("Counts D33 - spec 5 ($\AA$)$^{-1}$")
ax1.legend().draggable()
x_min, x_max = 0,10
ax1.set_xlim((x_min, x_max))
y1_min, y1_max = 0,35
ax1.set_ylim((y1_min, y1_max))

# Create a new Axes object that shares the x-axis and plot the next spectrum
ax2 = ax1.twinx()
ax2.plot(GEM38370_Focussed, specNum=6, color='r')
ax2.set_ylabel("Counts GEM - spec 6 ($\AA$)$^{-1}$")
ax2.legend().draggable()
y2_min, y2_max = 0,1400000
ax2.set_ylim((y2_min, y2_max))

plt.show()

The legends may appear on top of eachother!

Once plotted, double clicking on the axes should allow you to alter the min and max limits. This isn’t perfectly built for the GUI so for me it loads up an ‘Edit axis’ pop up window for Yaxis1, then after clicking OK a pop up window for Yaxis2 will appear.

Hopefully this is something we can look at improving in the future.