参考サイト
NumPyでヒストグラムを作るnp.histogram関数の使い方 - DeepAge
scipy.signal.peak_widths — SciPy v1.12.0 Manual
import numpy as np from scipy.signal import find_peak, peak_widths from matplotlib import pyplot as plt # data file: data.dat # data.dat has 2 raw data, and second raw data is to be plotted as a histogram # read data from data file data = np.loadtxt('data.dat').T # check histogram by plotting plt.hist(data[1]) plt.show() # get half maximum of full width of the histogram histogram = np.histgram(data[1]) # histogram[0]: intensity (y-axis) # histogram[1]: values (x-axis) peaks = find_peaks(histogram[0]) results_half = peak_widths(histogram[0], peaks, rel_height=0.5) half_widths = results_half[0] * (histgram[1][1] - histogram[1][0]) # check peak and widths by plotting plt.plot(histogram[0]) plt.plot(peaks, histogram[0][peaks], "x") plt.hlines(*results_half[1:]) plt.show()