简体   繁体   中英

Plot the peaks of a histogram

I'm trying to figure out how to plot the peaks of a simple histogram using scipy.signal.find_peaks but the peaks found seem way off.

ages = np.array([10, 5, 22, 13, 50, 45, 67, 30, 21, 34, 60, 67, 89, 45, 45, 65])
hist, bin_edges = np.histogram(ages, 10)
bin_edges = bin_edges[1:]

plt.plot(bin_edges, hist)
peaks, _ = find_peaks(hist)
plt.plot(ages[peaks], peaks, "x")

绘制的峰

You should try:

plt.plot(bin_edges[peaks], hist[peaks], "x")

find_peaks gives you the indices of local maxima in the hist signal.

The x-values of your histogram are bin_edges and the y-values are given by hist . So you have to look for the indices given by peaks in each of these series.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM