import argparse import numpy as np import matplotlib.pyplot as plt #parse the command line arguments parser = argparse.ArgumentParser(description="Plot a histogram") parser.add_argument("input_file",help="Path to the input data set with 7 columns") args = parser.parse_args() # Open the file and read in the data with open(args.input_file, 'r') as f: lines = f.readlines() # Extract the second column of data data = [] for line in lines: values = line.strip().split() if len(values) >= 7 and float(values[5]) == 0: data.append(float(values[6])) #determine histrange from data hist_range = 10 * 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=200, range=(hist_start,hist_end)) # Calculate the mean and RMS bin_centers = 0.5 * (bins[:-1] + bins[1:]) mean = np.average(bin_centers, weights=hist) rms = np.sqrt(np.average((bin_centers - mean)**2, weights=hist )) # Set the x-axis label and title plt.xlabel('time difference / seconds') plt.title(' - ') plt.annotate(f"Mean: {mean:.3g}\nRMS; {rms:.3g}", xy=(0.75, 0.85), xycoords='axes fraction', fontsize=12, bbox=dict(boxstyle="round,pad=0.3", edgecolor="gray", facecolor="lightgray")) # Show the plot plt.show()