Open the first file and push data in numpy.array for plotting -ray diffraction diagram.
时间: 2024-02-18 20:02:38 浏览: 96
Sure! Here is an example code to read the data and plot the X-ray diffraction diagram using matplotlib:
```python
import numpy as np
import matplotlib.pyplot as plt
filename = "drx-sample1.xy"
data = np.loadtxt(filename)
# Print the shape of the data array and the first 5 elements
print(data.shape)
print(data[:5])
# Plot the X-ray diffraction diagram
x = data[:, 0]
y = data[:, 1]
plt.plot(x, y)
plt.xlabel("2θ")
plt.ylabel("Intensity")
plt.title("X-ray Diffraction")
plt.show()
```
In this code, we first import numpy and matplotlib libraries. Then, we use the `loadtxt()` function from numpy to read the data from the file "drx-sample1.xy" and store it in a numpy array called `data`.
We then print the shape of the data array and the first 5 elements to verify that the data has been read correctly.
Finally, we plot the X-ray diffraction diagram using the data from the array. We extract the X and Y data from the array using indexing and plot them using the `plot()` function from matplotlib. We also add labels to the X and Y axes and a title to the plot using the `xlabel()`, `ylabel()`, and `title()` functions.
You can copy and paste this code in your Python environment and run it to plot the X-ray diffraction diagram for the first file.
阅读全文