\(\renewcommand\AA{\unicode{x212B}}\)

Python in Mantid: Exercise 3

A - Direct Matplotlib with SNS Data

  1. Load the processed CNCS data file Training_Exercise3a_SNS.nxs

  2. Directly using MPL (eg. axes.plot() ), plot the first 5 spectra

  3. Optionally set labels and colors for each spectrum

  4. Again directly in MPL, plot the final spectrum with errorbars

  5. Optionally, set a capsize > 0, and choose a color and label

  6. Rescale x-axis limits to -1.5 < x < 1.8

  7. Change the y-axis to have a log scale

  8. Give the plot a title, legend and don’t forget to show the plot

B - plotSpectrum with ISIS Data

  1. Load the GEM data set - GEM40979.raw using SpectrumMin=431 & SpectrumMax=750

  2. Convert units to dSpacing

  3. Smooth the data using SmoothData v1 using NPoints=20

  4. Using plotSpectrum(), plot workspace indices 0,1,2

  5. Set the x-axis limits to 4 < x < 6

  6. Set the y-axis limits to 0 < y < 5e3

  7. Again using plotSpectrum(), plot workspace index 5 on the same plot window

  8. Change the label of the Y axis

  9. Give the plot a legend with labels for each curve

  10. Give the plot a title

C - 2D and 3D Plot ILL Data

  1. Load the file 164198.nxs

  2. ExtractSpectra v1 using X range 470-490 and WorkspaceIndex range 199-209. Use this region of interest for plotting.

  3. Produce a figure and axes for subplots with ncols=2, nrows=1, using the mantid projection and also set the figsize = (6,4)

  4. Produce a 2D colorfill plot, using the imshow method, on both subplots (indexed as axes[0] and axes[1])

  5. For both set the colormap to jet and aspect=’auto’

  6. Overlay contour lines on the second subplot (axes[1]), colored white and with alpha = 0.5

  7. Set the title to ‘Colorfill’ for axes[0] and ‘Contour’ for axes[1]

  8. Add a colorbar to this figure

  9. Set the colorbar label to ‘Counts ($mu s$)$^{-1}$’

  10. Get another figure and axes for subplots with ncols=2, nrows=1, using the mantid3d projection and also set figsize = (8,3)

  11. Add a Surface and Wireframe plot to the subplot axes respectively (indexed as axes[0] and axes[1])

  12. Set the colormap for the surface plot to ‘summer’ and the color for the wireframe to ‘darkmagenta’

  13. Set the title for each subplot as ‘Surface’ and ‘Wireframe’

  14. Remember to show the plots

Solutions