Read and Export data¶
The functions in the previous tutorial make plotting pretty automatic, using matplotlib's standard style. But sometimes, you might just want to read the data without immediately plotting it—maybe to style it your own way or to convert it into a different format.
Customize spinplots¶
In the previous tutorial, we used bruker1d(['../../data/1D/glycine/pdata/1'], xlim=(250, -20))
to create a simple 13C NMR plot. By adding the option return_fig=True
, you can return the figure object, which allows you to further customize the appearance of the spectrum as you like.
gly = read_nmr("../../data/1D/glycine/pdata/1")
fig, ax = gly.plot(xlim=(250, -20), return_fig=True)
ax.set_title("Customized plot")
ax.set_xlabel("13-Carbon NMR in ppm")
ax.lines[0].set_color("purple")
ax.lines[0].set_linewidth(2)
ax.lines[0].set_linestyle("-.")
fig.savefig("../../data/1D/customized_plot.png")
Export data to Pandas and CSV¶
A different option is to use the nmr_df
function from spinplots.utils
to get a Pandas DataFrame. This way, you can manipulate the data however you like before plotting.
Convert data in the terminal¶
Pandas DataFrames can be easily exported to other formats such as .csv
. You can do this directly in your code with df.to_csv('exported_data.csv')
, or use the bruker2csv
function from the terminal for a quick export.