36 lines
873 B
Python
36 lines
873 B
Python
import numpy as np
|
|
import matplotlib.pyplot as plt
|
|
|
|
# Open the file and read in the data
|
|
with open('../data/test02.dat', 'r') as f:
|
|
lines = f.readlines()
|
|
|
|
# Extract the second column of data
|
|
data = []
|
|
for line in lines:
|
|
values = line.strip().split()
|
|
data.append(float(values[1]))
|
|
|
|
#determine histrange from data
|
|
hist_range = 5 * np.std(data)
|
|
hist_mean = np.mean(data)
|
|
hist_start = hist_mean - hist_range
|
|
hist_end = hist_mean + hist_range
|
|
|
|
# Create the histogram with range
|
|
hist, bins, _ = plt.hist(data, bins=100, range=(hist_start,hist_end))
|
|
|
|
# Calculate the mean and RMS
|
|
bin_centers = 0.5 * (bins[:-1] + bins[1:])
|
|
|
|
# Set the x-axis label and title
|
|
plt.xlabel('Data')
|
|
plt.title('Histogram of Data')
|
|
|
|
# Show the plot
|
|
plt.show()
|
|
|
|
# Print the mean and RMS
|
|
print(f"Mean: {np.mean(data):.3g}")
|
|
print(f"RMS: {np.std(data):.3g}")
|