您说:
在Linux终端中将.Spe后缀修改成.txt的命令
python# Reverting back to the original x-axis settings, without explicitly marking the endpoint
plt.figure(figsize=(10, 6))
plt.bar(channels, alpha_particle_counts, color='blue', label='Alpha Particle Counts')
# Plot the curve connecting the top of the bars
plt.plot(channels, alpha_particle_counts, color='red', linestyle='-', label='Connecting Curve')
# Labeling the axes
plt.xlabel('Channels')
plt.ylabel('Alpha Particle Counts')
# Add a legend without focusing on 1023 explicitly
plt.legend()
# Show the plot with a title
plt.title("Alpha Particle Counts Across Channels")
plt.show()
python# Reading the new file and extracting the data between "0 1023" and "$ROI"
new_file_path_3 = '/mnt/data/alpha4.4.1.txt'
# Reading the new file and processing it
with open(new_file_path_3, 'r') as file:
lines = file.readlines()
# Finding the indices of the "0 1023" and "$ROI"
start_index = None
end_index = None
for i, line in enumerate(lines):
if "0 1023" in line:
start_index = i + 1
elif "$ROI" in line:
end_index = i
break
# Extracting the data between the two indices
if start_index is not None and end_index is not None:
data_lines = lines[start_index:end_index]
# Converting the data to integers
new_data_3 = [int(line.strip()) for line in data_lines if line.strip().isdigit()]
# Prepare data for the plot
channels = np.arange(1024)
alpha_particle_counts_new_3 = np.array(new_data_3)
# Calculate the total count of alpha particles
total_alpha_particles_new_3 = sum(alpha_particle_counts_new_3)
# Create a bar plot
plt.figure(figsize=(10, 6))
plt.bar(channels, alpha_particle_counts_new_3, color='blue', label='Alpha Particle Counts')
# Plot the curve connecting the top of the bars
plt.plot(channels, alpha_particle_counts_new_3, color='red', linestyle='-', label='Connecting Curve')
# Labeling the axes
plt.xlabel('Channels')
plt.ylabel('Alpha Particle Counts')
# Adding a text box with two lines of information: total time and total alpha particles
textstr = '\n'.join((
r'Total Time: 500s',
f'Total Alpha Particles: {total_alpha_particles_new_3}'
))
# Adding the textbox above the x-coordinate of 600, left-aligned
props = dict(boxstyle='round', facecolor='white', alpha=0.5)
plt.text(0.6, 0.8, textstr, transform=plt.gca().transAxes, fontsize=12,
verticalalignment='top', horizontalalignment='left', bbox=props)
# Add a legend
plt.legend()
# Show the plot with a title
plt.title("Alpha Particle Counts Across Channels (with Time and Total Count Info)")
plt.show()