give me a code to invert the x axis for this code of an NMR
- User
give me a code to invert the x axis for this code of an NMR
- Assistant
To invert the x-axis for an NMR code, you can modify the x-axis data points by subtracting each value from the maximum x-axis value. Here's an example code snippet in Python:
import matplotlib.pyplot as plt # Sample data for x-axis and y-axis x = [1, 2, 3, 4, 5] # Replace with your own data y = [10, 20, 30, 40, 50] # Replace with your own data # Invert the x-axis max_x = max(x) inverted_x = [max_x - x_val for x_val in x] # Plot the inverted NMR spectrum plt.plot(inverted_x, y) plt.xlabel('Inverted X-axis') plt.ylabel('Intensity (Y-axis)') plt.title('Inverted NMR Spectrum') plt.grid(True) plt.show()This code snippet uses the
matplotliblibrary to create a plot of the inverted NMR spectrum. Replace thexandylists with your own data. - User
give me a code to invert the x axis for this code of an NMRimport numpy as np import matplotlib.pyplot as plt
Load data from text files
data1 = np.genfromtxt('data/ethyl_cyanoacetate.txt', delimiter='\t', skip_header=1) data2 = np.genfromtxt('data/ethyl_phenylcyanoacetate.txt', delimiter='\t', skip_header=1)
Create figure and subplots
fig, axes = plt.subplots(nrows=2, ncols=2, figsize=(10, 8))
Plot the original data for entire spectrum
axes[0, 0].plot(data1[:, 0], data1[:, 1], 'b', linewidth=1) axes[0, 0].set_title('Ethyl Cyanoacetate - Full Spectrum') axes[0, 0].set_xlabel('Chemical Shift (ppm)') axes[0, 0].set_ylabel('Intensity')
axes[0, 1].plot(data2[:, 0], data2[:, 1], 'r', linewidth=1) axes[0, 1].set_title('Ethyl Phenylcyanoacetate - Full Spectrum') axes[0, 1].set_xlabel('Chemical Shift (ppm)') axes[0, 1].set_ylabel('Intensity')
Plot the cropped region around 4.45 and 4.15 ppm
crop_data1 = data1[42300:45100, :] crop_data2 = data2[42300:45100, :]
axes[1, 0].plot(crop_data1[:, 0], crop_data1[:, 1], 'b', linewidth=1) axes[1, 0].set_title('Ethyl Cyanoacetate - Cropped Spectrum') axes[1, 0].set_xlabel('Chemical Shift (ppm)') axes[1, 0].set_ylabel('Intensity')
- Assistant
To invert the x-axis for the given NMR code, you can modify the x-axis data points in the same way as mentioned in the previous response. Here's an updated code snippet:
import numpy as np import matplotlib.pyplot as plt # Load data from text files data1 = np.genfromtxt('data/ethyl_cyanoacetate.txt', delimiter='\t', skip_header=1) data2 = np.genfromtxt('data/ethyl_phenylcyanoacetate.txt', delimiter='\t', skip_header=1) # Invert the x-axis for entire spectrum inverted_data1 = np.copy(data1) inverted_data1[:, 0] = max(data1[:, 0]) - data1[:, 0] inverted_data2 = np.copy(data2) inverted_data2[:, 0] = max(data2[:, 0]) - data2[:, 0] # Create figure and subplots fig, axes = plt.subplots(nrows=2, ncols=2, figsize=(10, 8)) # Plot the inverted data for entire spectrum axes[0, 0].plot(inverted_data1[:, 0], inverted_data1[:, 1], 'b', linewidth=1) axes[0, 0].set_title('Ethyl Cyanoacetate - Full Spectrum') axes[0, 0].set_xlabel('Inverted Chemical Shift (ppm)') axes[0, 0].set_ylabel('Intensity') axes[0, 1].plot(inverted_data2[:, 0], inverted_data2[:, 1], 'r', linewidth=1) axes[0, 1].set_title('Ethyl Phenylcyanoacetate - Full Spectrum') axes[0, 1].set_xlabel('Inverted Chemical Shift (ppm)') axes[0, 1].set_ylabel('Intensity') # Plot the cropped region around 4.45 and 4.15 ppm crop_data1 = inverted_data1[42300:45100, :] crop_data2 = inverted_data2[42300:45100, :] axes[1, 0].plot(crop_data1[:, 0], crop_data1[:, 1], 'b', linewidth=1) axes[1, 0].set_title('Ethyl Cyanoacetate - Cropped Spectrum') axes[1, 0].set_xlabel('Inverted Chemical Shift (ppm)') axes[1, 0].set_ylabel('Intensity') axes[1, 1].plot(crop_data2[:, 0], crop_data2[:, 1], 'r', linewidth=1) axes[1, 1].set_title('Ethyl Phenylcyanoacetate - Cropped Spectrum') axes[1, 1].set_xlabel('Inverted Chemical Shift (ppm)') axes[1, 1].set_ylabel('Intensity') # Adjust spacing between subplots plt.tight_layout() # Show the plot plt.show()