Easy plots
The current version of SpinPlots
only works with processed Bruker data. If you’re dealing with unprocessed data or using data from a different brand, we recommend using NMRglue instead. Also, if you want more control over the looks of your plot, SpinPlots
might feel a bit limited since it mostly sticks to the default matplotlib style for now.
Plot 1D spectra¶
The easiest way to plot a spectrum is as follows
SpinPlots
uses Matplotlib's standard style by default. If you want to customize the appearance of your spectra, you can use the option return_fig=True
. This allows you to return the figure object and modify it as needed before displaying or saving it.
The bruker1d
function has a bunch of useful features beyond just making a simple plot. Some of the key ones include:
- Plotting several plots together
- Plot with/without frame
- Labelling of spectra
- Normalization of data
- Select colors for each spectrum using matplotlib's colors
- Saving the plot directly to a file
Here’s an example that highlights most of these features:
path = '../../data/1D/'
bruker1d([path + '8/pdata/1', path + '12/pdata/1', path + '33/pdata/1', path + '39/pdata/1'],
labels=['Sample A', 'Sample B', 'Sample C', 'Sample D'],
color=['brown', 'teal', 'skyblue', 'sandybrown'],
xlim=(250, -20),
frame=False,
normalized=False,
save=True,
filename='../../data/1D/overlapped',
format='png')
Stacked 1D spectra¶
You can also opt by stacking the plots, using the stacked
keyword, as shown below:
The bruker1d_grid
function works similarly to bruker1d
, but instead of overlapping the spectra, it lets you arrange them in a grid (subplots).
Here’s an example of how it works:
path = '../../data/1D/'
bruker1d_grid([path + '8/pdata/1', path + '12/pdata/1', path + '33/pdata/1', path + '39/pdata/1'],
labels=['Sample A', 'Sample B', 'Sample C', 'Sample D'],
xlim=(250, -20),
subplot_dims=(2, 2),
frame=False,
normalized=True,
save=True,
filename='../../data/1D/grid',
format='png')
Plot 2D spectra¶
Lastly, the bruker2d function makes it super easy to plot 2D NMR spectra. You just need to provide a bit more info to customize the plot. Here’s what you can specify:
- countour_start
: the minimum value for the contour plot
- countour_num
: how many contour levels you want
- countour_factor
: the factor between each contour level
- cmap
: the matplotlib colormap for countour (default is 'black')
- xlim
: limits for the x-axis, i.e. direct dimension (F2)
- ylim
: limits for the y-axis, i.e. indirect dimension (F1)
- save
: whether you want to save the plot
- filename
: the name to save the plot as
- format
: the file format to save it
Some NMR spectra, like double-quantum (DQ) experiments, are often visualized with a diagonal line representing y=2x
. You can add this diagonal line for any line of the form y=nx
using the keyword diag=n
, where n
sets the desired quantum order. Here’s an example of a 13C-13C DQ-SQ experiment. The option homo=True
is only needed if the y-axis label isn’t displaying correctly, such as when the DQ-SQ is acquired through CPMAS.