|
1 | 1 | # The code creates a normalized plot using the matplotlib library in Python. It imports the necessary
|
2 | 2 | # libraries (matplotlib.pyplot, numpy, and sys) and defines a conversion factor from inverse
|
3 |
| -# centimeters to electron volts. Plots the reference data, which is the first argument and |
4 |
| -#, then plot the remaining spectra arguments 2 and onwards and align them with respect to the |
5 |
| -# desired offset. Here, it aligns with the first index of the x-axis of the reference data. |
| 3 | +# centimeters to electron volts. Plots the reference data, which is the first argument and |
| 4 | +# , then plot the remaining spectra arguments 2 and onwards and align them with respect to the |
| 5 | +# desired offset. Here, it aligns with the first index of the x-axis of the reference data. |
6 | 6 | import matplotlib.pyplot as plt
|
7 | 7 | import numpy as np
|
8 | 8 | import sys
|
9 | 9 |
|
10 |
| -# Conversion factor |
11 |
| -invcm_to_eV = 1.0/8065.54429 |
| 10 | +# Conversion factor |
| 11 | +invcm_to_eV = 1.0 / 8065.54429 |
12 | 12 | offset = int(0)
|
13 | 13 |
|
14 | 14 | # Set up plot
|
15 |
| -fig, axs = plt.subplots(1, 2, figsize=(10,5)) |
| 15 | +fig, axs = plt.subplots(1, 2, figsize=(10, 5)) |
16 | 16 | filename = str(sys.argv[1])
|
17 |
| -ref_data = np.loadtxt(f'{filename}', skiprows=7, usecols=(0,1,2)) |
18 |
| -ref_data[:,0] = ref_data[:,0] * invcm_to_eV |
| 17 | +ref_data = np.loadtxt(f"{filename}", skiprows=7, usecols=(0, 1, 2)) |
| 18 | +ref_data[:, 0] = ref_data[:, 0] * invcm_to_eV |
19 | 19 |
|
20 | 20 | # Plot reference
|
21 |
| -axs[0].plot(ref_data[:,0], ref_data[:,1]/ref_data[:,1].max(), label='Explicit') |
22 |
| -axs[1].plot(ref_data[:,0], ref_data[:,2]/ref_data[:,2].max(), label='Explicit') |
| 21 | +axs[0].plot(ref_data[:, 0], ref_data[:, 1] / ref_data[:, 1].max(), label="Explicit") |
| 22 | +axs[1].plot(ref_data[:, 0], ref_data[:, 2] / ref_data[:, 2].max(), label="Explicit") |
23 | 23 |
|
24 |
| -# Process each file provided as command line argument |
| 24 | +# Process each file provided as command line argument |
25 | 25 | for i, filename in enumerate(sys.argv[2:]):
|
26 | 26 |
|
27 | 27 | # Load data
|
28 |
| - data = np.loadtxt(filename, skiprows=7, usecols=(0,1,2)) |
29 |
| - |
| 28 | + data = np.loadtxt(filename, skiprows=7, usecols=(0, 1, 2)) |
| 29 | + |
30 | 30 | # Convert x-axis to eV
|
31 |
| - data[:,0] = data[:,0] * invcm_to_eV |
32 |
| - |
| 31 | + data[:, 0] = data[:, 0] * invcm_to_eV |
| 32 | + |
33 | 33 | # Normalize y-axis
|
34 |
| - data[:,1] /= data[:,1].max() |
35 |
| - data[:,2] /= data[:,2].max() |
| 34 | + data[:, 1] /= data[:, 1].max() |
| 35 | + data[:, 2] /= data[:, 2].max() |
36 | 36 |
|
37 |
| - label = f'File {i+1}' |
| 37 | + label = f"File {i+1}" |
38 | 38 |
|
39 | 39 | # Plot 0K data
|
40 | 40 | if i == 0:
|
41 |
| - # Reference plot |
42 |
| - axs[0].plot(data[:,0], data[:,1], label=label) |
| 41 | + # Reference plot |
| 42 | + axs[0].plot(data[:, 0], data[:, 1], label=label) |
43 | 43 | else:
|
44 |
| - # Align to reference |
45 |
| - offset = data[offset,offset] - ref_data[offset,offset] |
46 |
| - axs[0].plot(data[:,0] - offset, data[:,1]/ref_data[0,1], label=label) |
| 44 | + # Align to reference |
| 45 | + offset = data[offset, offset] - ref_data[offset, offset] |
| 46 | + axs[0].plot(data[:, 0] - offset, data[:, 1] / ref_data[0, 1], label=label) |
47 | 47 |
|
48 | 48 | # Plot 300K data
|
49 | 49 | if i == 0:
|
50 |
| - # Reference plot |
51 |
| - axs[1].plot(data[:,0], data[:,2], label=label) |
| 50 | + # Reference plot |
| 51 | + axs[1].plot(data[:, 0], data[:, 2], label=label) |
52 | 52 | else:
|
53 |
| - # Align to reference |
54 |
| - offset = data[0,0] - ref_data[0,0] |
55 |
| - axs[1].plot(data[:,0] - offset, data[:,2]/ref_data[0,2], label=label) |
56 |
| - |
57 |
| -# Add axes labels |
58 |
| -axs[0].set_xlabel('Energy (eV)') |
59 |
| -axs[0].set_ylabel('Intensity') |
60 |
| -axs[1].set_xlabel('Energy (eV)') |
61 |
| -axs[1].set_ylabel('Intensity') |
| 53 | + # Align to reference |
| 54 | + offset = data[0, 0] - ref_data[0, 0] |
| 55 | + axs[1].plot(data[:, 0] - offset, data[:, 2] / ref_data[0, 2], label=label) |
| 56 | + |
| 57 | +# Add axes labels |
| 58 | +axs[0].set_xlabel("Energy (eV)") |
| 59 | +axs[0].set_ylabel("Intensity") |
| 60 | +axs[1].set_xlabel("Energy (eV)") |
| 61 | +axs[1].set_ylabel("Intensity") |
62 | 62 |
|
63 | 63 | # Add legend
|
64 | 64 | axs[0].legend()
|
65 |
| -axs[1].legend() |
| 65 | +axs[1].legend() |
66 | 66 |
|
67 | 67 | # Set axes limits
|
68 |
| -axs[0].set_ylim(0, 1.1) |
| 68 | +axs[0].set_ylim(0, 1.1) |
69 | 69 | axs[1].set_ylim(0, 1.1)
|
70 | 70 |
|
71 | 71 | # Set number of ticks
|
72 |
| -axs[0].locator_params(axis='x', nbins=5) |
73 |
| -axs[1].locator_params(axis='x', nbins=5) |
| 72 | +axs[0].locator_params(axis="x", nbins=5) |
| 73 | +axs[1].locator_params(axis="x", nbins=5) |
74 | 74 |
|
75 | 75 | # Save figure
|
76 | 76 | fig.tight_layout()
|
77 |
| -fig.savefig('plot.png', dpi=300) |
| 77 | +fig.savefig("plot.png", dpi=300) |
0 commit comments